Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Latest commit

 

History

History
35 lines (26 loc) · 911 Bytes

validation.md

File metadata and controls

35 lines (26 loc) · 911 Bytes

Model validation

A Model manages all its Property objects and provide the validate() method and the valid and validationErrors observables.

var App = blocks.Application();

var User = App.Model({
  username: App.Property({
    required: 'Username is required!'
  }),

  email: App.Property({
    email: 'Please provide a valid email!'
  })
});

var user = User({
  username: '',
  email: 'email@gmail'
});

// validate the username and email properties
user.validate();

// alerts 'false' (both username and email failed validation)
alert(user.valid());

// alerts 'Username is required!,Please provide a valid email!'
// validationErrors is an array of all validation error messages
// constructed from extracting the values from all properties errorMessages collection
alert(user.validationErrors());

For more information about validation go here.