Slide 1

Slide 1 text

can-form Awesome forms for CanJS

Slide 2

Slide 2 text

Why? • validations and error reporting is a pain • similar code written over and over again • how do you handle nested object structures?

Slide 3

Slide 3 text

can-form • can-value is great, use it • behaves like the can.Component • composable / nestable (allows it to handle nested structures) • validations on the form (validations are bound to context) • simple error reporting and tracking

Slide 4

Slide 4 text

API FormComponent.extend({ tag : 'simple-form', template : '', validate : { username : [FormComponent.validationRules.presenceOf()], password : [FormComponent.validationRules.presenceOf()] } }); {{#errors 'username'}}
    {{#this}}
  • {{ . }}
  • {{/this}}
{{/errors}} {{#errors 'password'}}
    {{#this}}
  • {{ . }}
  • {{/this}}
{{/errors}} Submit

Slide 5

Slide 5 text

API FormComponent.extend({ tag : 'simple-form', template : '', validate : { username : [FormComponent.validationRules.presenceOf()], password : [FormComponent.validationRules.presenceOf()], 'socialNetworks.*.username' : [FormComponent.validationRules.presenceOf()], 'socialNetworks.*.network' : [FormComponent.validationRules.presenceOf()] } });

Slide 6

Slide 6 text

API {{#errors 'username'}}
    {{#this}}
  • {{ . }}
  • {{/this}}
{{/errors}} … ! {{#each socialNetworks}} // error reporting code here // error reporting code here {{/each}} Submit

Slide 7

Slide 7 text

API FormComponent.extend({ tag : 'social-network', template : socialNetworkTemplate, validate : { username : [FormComponent.validationRules.presenceOf()], network : [FormComponent.validationRules.presenceOf()] } })

Slide 8

Slide 8 text

API {{#errors 'username'}}
    {{#this}}
  • {{ . }}
  • {{/this}}
{{/errors}} ! … ! {{#each socialNetworks}} {{/each}} ! Submit

Slide 9

Slide 9 text

github.com/retro/can-form @mihaelkonjevic