i have some problems with Backbone.Validation library, as you know model.bind("validated", function(...) ). i have that one in method of Reactjs Component. You can see the code as below, i would like to set the eMsg global var but when it outside of user.bind or user.on, eMsg var is not assign.
How can i get error from user.bind or user.on to outside of the statement ? Thanks.
handleSubmit : function() {
var self = this;
var user = new global.Models.RegisterModel(this.state.model, {validate:true});
var flag = false;
var eMsg = null;
********* (First Testing) ************
/*user.bind("validated", function(isValid, model, error) {
if(!isValid){
for (var k in error) {
eMsg += ", " + error[k];
}
}else{
flag = true;
}
});*/
********* (Sencod Testing) ************
if( user.isValid() ){
console.log("success")
this.setState({msg : "success"})
}else{
console.log("error")
user.on("invalid", function(model, error) {
console.log("invalid")
console.log(error);
})
this.setState({msg : eMsg})
}
}
Aucun commentaire:
Enregistrer un commentaire