CouchTypes forms

You must be logged in to edit this page
### Previously In the previous section we instantiated a form passing parameters to it ```javascript {first_name: fields.string(), last_name: fields.string()} ``` Let's make use of one of the most useful feature of Kanso : CouchTypes ### Files it relies on ``` example-app |-- lib |-- types.js ``` Among the files previously mentionned, in order to use CouchTypes we need to edit the auto generated file `types.js` ### types.js ```javascript var Type = require('couchtypes/types').Type, fields = require('couchtypes/fields'), widgets = require('couchtypes/widgets'); exports.person = new Type('person', { fields : { first_name: fields.string(), last_name: fields.string() } }); ``` We just created a document type : person. A person document type has two string fields. For more informations about CouchTypes please refer to [[Getting_started_with_CouchTypes]] ### shows.js and updates.js ```javascript var person = require('./types').person; ``` First, require the person type so it can be used in the file. Then replace ```javascript new Form({first_name: fields.string(), last_name: fields.string()}); ``` With ```javascript new Form(person); ``` Now the form will render according to the type intrinsic widget fields properties ### Next Now that we know how to create a form that relies on CouchTypes. Let's go a step forward and see how on can customize the widget property : [[Custom_widgets]]