dart - Is it possible to set the valid property of a Control? -
given control titlectrl, there way set valid property?
i tried
.dart
titlectrl.valid = false;
but throws error. getting valid state no problem though.
the valid
property of control
read property. cannot assign value. correct way have become invalid create custom validator
here example code snippet angular2 typescript documentation
class customvalidatordirective implements validator { validate(c: control): {[key: string]: any} { return {"custom": true}; } }
your validations not need in separate class though, when create controlgroup
using formbuilder
can set custom validations on individual controls.
@component({...}) class mycomponent{ myform: controlgroup; constructor(formbuilder: formbuilder){ this.myform = formbuilder.group({ myfield: ['', validators.compose([this.customvalidation.bind(this)])], }); } customvalidation(control: control){ if(/* condition */){ return {'myvalidatorkey': true}; } } }
this technique can used validate field including fields dependent on values of other fields , other logic.
sadly angular2 team hasn't released documentation on dart usage cannot provide examples in dart, have attempted remove typescript specific noise make answer generic possible.
Comments
Post a Comment