Skip to content

Instantly share code, notes, and snippets.

@taburetkin
Created September 11, 2018 10:33
Show Gist options
  • Save taburetkin/faff5a397a0c6958e85d899cafa4429a to your computer and use it in GitHub Desktop.
Save taburetkin/faff5a397a0c6958e85d899cafa4429a to your computer and use it in GitHub Desktop.
edit-model-property control
import ControlWrapper from 'components/controls/wrapper';
import Input from 'components/controls/input';
import { textView } from 'base/view';
import { validateItem } from 'helpers/validation';
export default ControlWrapper.extend({
shouldShowError: true,
className:'edit-model-property',
constructor(options = {}){
ControlWrapper.apply(this, arguments);
this.mergeOptions(options, ['propertySchema','property']);
//this.on('all', c => Console.log(this.property, '=>', c));
},
getHeaderView(){
let text = this.propertySchema.getLabel();
return text && textView({ text, tagName:'header' });
},
getControlView(){
return new Input({
value: this.getControlValue(),
valueOptions: this.propertySchema.getType(),
inputAttributes:{
name: this.property,
},
proxyTo: this,
});
},
controlValidate(value, fullValue){
let rule = this._getValidateRule();
if(!rule || !_.size(rule)) return;
return validateItem(value, rule, { fullValue });
},
_getValidateRule(){
if (!this.propertySchema) return;
if (!this._validateRule) {
this._validateRule = _.extend({}, this.propertySchema.getType(), this.propertySchema.getValidation());
}
return this._validateRule;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment