Flagrate API documentation

Home ▲
constructor

flagrate.createForm

flagrate.createForm(option) → flagrate.Form
new flagrate.Form

Create and initialize the Form.

option

field

input

depend

inputType

if specified a String, will use flagrate.Form.inputType[(specified)].

inputValidator

if specified a String, will use flagrate.Form.inputValidator[(specified)].

// Example: custom validator
validators: [
  // using regex:
  {
    regexp: /^[a-z0-9]+(-[a-z0-9]+)*(\.([a-z0-9]+(-[a-z0-9]+)*))*$/i,
    error: 'Please enter a valid hostname string.'
  },
  // using async function:
  function (input, done) {
    someAsyncFunction(input, function (err, result) {
      if (err) {
        done('error', 'This hostname is already in use. (' + err + ')');
      } else {
        done('success');
      }
    });
  },
  // using sync function:
  function (input, done) {
    var err = someSyncFunction(input);
    if (err) {
      done('error', 'This hostname is prohibited. (' + err + ')');
    } else {
      done('success');
    }
  }
]

see flagrate.Form.inputValidator to read more documents.