Skip to content
gvilarino edited this page Dec 9, 2014 · 2 revisions

FormView

The FormView base class is located under the lib/form-view directory.

This class - like View - is passed a template and the locals for that template.

function FormView(template, options) {
  if (!(this instanceof FormView))
    return inherit(template, FormView);

  View.call(this, template, options);

  this.autovalidate('form[autovalidate]');
  this.autosubmit('form[autosubmit]');
  this.on('insert', this.bound('oninsert'));
  this.on('remove', this.bound('onremove'));
  this.messages();
}

Autovalidate

To use the autovalidate capabilities just add [autovalidate='autovalidate'] on the form tag inside the template.jade. Also, to any input being validated add the validate='validationName' attribute.

If the field has many validations, add them separating them with spaces, like: validate='required url'.

validationName must match a validator function on lib/validators/validators.js.

Autosubmit

To use the autosubmit capabilities just add [autosubmit='autosubmit'] on the form tag inside the template.jade. The FormView gets the action attribute and performs a request to that URL, disabling the form submit button.

If the request comes back with an error, then it is shown by the errors FormView method.

If not, and the requests is successful, the FormView emits a 'success' event, which you can subscribe to and handle the happy path.