Form events

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:

  • invalid - One or more form fields has an invalid value according to it's validation routine, example: missing or invalid email address.
  • clean - No changes has been made to any of the form fields.
  • dirty - Changes has been made to one or more form fields, i.e. current value != initial.
  • change - Fired after changes has been made to one of the form fields. Here, current value can be equal to initial.

  • submit.init - Fired just before the form is submitted
  • submit.success - Fired after successful form submission
  • submit.fail - Fired after failed form submission

  • read.init - Fired just before reading form data from server
  • read.success - Fired after form data successfully has been read from server
  • read.fail - Fired after failed attempt reading form data from server.
Generated 2016-12-02 19:27:14