CouchTypes forms

Previously

In the previous section we instantiated a form passing parameters to it

{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

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

var person = require('./types').person;

First, require the person type so it can be used in the file.

Then replace

new Form({first_name: fields.string(), last_name: fields.string()});

With

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