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 usage cannot provide examples in , have attempted remove typescript specific noise make answer generic possible.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -