Submit forms

A form is submitted using the forms submit method.

var view = new ludo.View({
    form:{
    },
    children:[
        { type:"form.Text", name:"firstname", value:"Jane" },
        { type:"form.Text", name:"lastname", value: "Peterson" }
    ]
})
view.getForm().submit();

Before a form can be submitted, we need to configure form submission. This is done using in a submit object like below:

var view = new ludo.View({
    form:{
        submit: {
            url : 'save.html',
            data:{ save: 1 },
            method:'post',
            listeners:{
                init: function(form){},
                success: function(json, form){},
                fail: function(text, error, form) {}
            }
        }
    },
    children:[
        { type:"form.Text", name:"firstname", value:"Jane" },
        { type:"form.Text", name:"lastname", value: "Peterson" }
    ]
})
view.getForm().submit();

These are the available properties:

  • url - where to submit data. If the same url is used for all form handling, you can specify url on the top form object.
  • data - Additional data to pass with the submit request. In this example, we will post { "save": 1, "firstname": "Jane", "lastname": "Peterson" }
  • method - Ajax method, default: "post"
  • listeners An object with event listener functions. The init function is fired before the submit request is sent. success will be fired on success, while fail will be triggered if the server didn't handle the submit request properly.

In the example above, data will be saved to the file save.html. The form will be submitted using jQuery Ajax. These data will be sent:

{
    "save": 1,
    "firstname": "Jane",
    "lastname": "Peterson"
}

"save": 1 is defined in the data object. firstname and lastname are form fields.

Generated 2016-12-02 19:27:14