You are here : Home > Learning Center > Tutorials > Forms

Forms

In this tutorial, we will look into how we work with forms in LudoJS.

In LudoJS, you have many form views, example: A Text Input field. All form views are found in the ludo.form name space.

A "form" is a collection of such form fields. In standard HTML, you use the <form> tag. In LudoJS, you define a form, by creating a form object on a View:

var view = new ludo.View({
    form:{
        // form configuration
    },
    children:[
        { type:"form.Text", name:"firstname" },
        { type:"form.Text", name:"lastname" }
    ]
})

This view will then be a form for all the views in it's view hierarchy(children, grand children etc).

When the form object is defined, a new ludo.form.Manager instance is created. ludo.form.Manager is a class with many convenient methods for working with forms fields.

The ludo.form.Manager instance is accessible from

view.getForm();

Example, to submit a form, you can call

view.getForm().submit();

and to update values of multiple form fields in one go, you can call the populate method:

view.getForm().populate({
    'firstname': 'John', lastname:'Peterson'
});
Generated 2016-12-02 19:27:14