A LudoJS form is aware of it's form fields and will trigger events on behalf of it's fields.
Adding listeners to the form is in most cases a better approach than adding listeners to the individual form fields.
To assign listeners, you can define them in a listener object
var view = new ludo.View({
renderTo:document.body,
layout:{
type:'linear', orientation:'vertical', height:'wrap', width: 500
},
form:{
listeners:{
'valid': function(form){
// Fired when all form fields has a valid value
}
},
submit:{
listeners:{
'init': function(form){
// before form submission
},
success:function(json, form){
// after successful submission
},
fail:function(text, error, form){
// after failed form submission
}
}
},
read:{
listeners:{
'init': function(form){
// before reading data from server
},
success:function(json, form){
// after successfully reading data from server
},
fail:function(text, error, form){
// after failed attempt reading data from server
}
}
}
},
children:[
{ type:'form.Text', name:'firstname', placeholder:'First name'},
{ type:'form.Text', name:'lastname', placeholder:'Last name'}
]
});
These are events you can listen to:
change - Fired after changes has been made to one of the form fields. Here, current value can be equal to initial.
submit.fail - Fired after failed form submission