Namespace: settings

settings

vulcanval validation settings by default.

When using validation methods you have to pass an object settings to configure the validation process which will overwrite this settings used by default.

Namespaces

validators

Members


<static> autostart :Boolean

Only client-side.

Validate field elements on instance time.

Type:
  • Boolean
Default Value:
  • false

<static> classes :Object

Only client-side.

HTML tag classes to add to specific elements in form on default and on error.

Type:
  • Object
Properties:
Name Type Argument Description
defaults Object <optional>

Static classes.

Properties
Name Type Argument Description
form String <optional>

Form classes.

field String <optional>

Field classes.

label String <optional>

Field related label classes.

display String <optional>

Display classes.

error Object <optional>

On error classes.

Properties
Name Type Argument Description
form String <optional>

Form classes.

field String <optional>

Field classes.

label String <optional>

Field related label classes.

display String <optional>

Display classes.


<static> disabled :Boolean

Form will not be instantiated. In client side, if <form> has the attribute disabled, this will be enabled.

Type:
  • Boolean
Default Value:
  • false

<static> disableHTML5Validation :Boolean

Only client-side.

Disable HTML5 validation with novalidate attribute when instanced on <form>. This is enabled if attribute "novalidate" is present.

Type:
  • Boolean
Default Value:
  • false

<static> enableNestedMaps :Boolean

When a map of fields is created out of a form, should it be converted to a map of nested fields or only plain fields?

Validation methods use this property to convert data maps from nested maps to plain maps when this property is enabled.

Type:
  • Boolean
Default Value:
  • false
See:
Example
// Using a form like this:
// <form>
//  <input name="field1" />
//  <input name="map1.field2" />
//  <input name="map1.field3" />
//  <input name="map2.field4" />
// </form>

const map = $('form').vulcanval('getMap');

// If nested maps are enabled, the map object will have this value:
// { field1: '', map1: { field2: '', field3: '' }, map2: { field4: '' } }

// Otherwise:
// { field1: '', 'map1.field2': '', 'map1.field3': '', 'map2.field4': '' }

<static> fields :Array

The form fields to configure.

Type:
  • Array
Default Value:
  • [ ]
See:

<static> fieldsets :Array

The form fieldsets to configure.

Type:
  • Array
Default Value:
  • [ ]
See:

<static> firstValidationEvent :String

Only client-side.

What event to listen to trigger the first validation on fields.

Type:
  • String
Default Value:
  • 'blur change'

<static> intern :Boolean

Only client-side.

When a field is validated, don't show changes visually nor show messages. This is used to know whether they are valid or not, update the fields elements states and trigger events.

Type:
  • Boolean
Default Value:
  • false

<static> locale :String

Default messages locale.

Type:
  • String
Default Value:
  • 'en'

<static> msgs :Object

Validators messages formats. This is an a plain object with keys as validator names and values as messages formats. The messages can be configured by locale otherwise the messages will be for the validator regardless the locale configured.

If a validator does not have a message for a locale, it will use the message general in the locale.

The formats can have some variables expressed as {{var}} where var is the variable name.

  • The variable {{value}} is always present to use and it's the value of the field validating.
  • The variable {{option}} can be used when the validator is configured with an string. Ex: in validator isAlphanumeric: 'de-DE', the variable will have the de-DE value. This also applies to numbers.
  • If the validator is configured with an object, then its properties are available as variables. Ex: in isInt: {min:4, max:8}, {{min}} and {{max}} will be available as variables in the message.

There is one exception, the validator isLength can have an specific message for its two properties to configure, min and max values. Other validators only have messages regardless the properties passes to it. See examples.

Also, the order of validator messages on errors can vary.

Type:
  • Object
Default Value:
  • {}
Example
const map = {
  username: 'Romel Pérez',
  age: 720
};

const settings = {

  locale: 'es',
  msgs: {

    // Used regardless the locale.
    isAlphanumeric: 'Debe ser alfanumérico en local "{{option}}".',

    // Configured by locale.
    isInt: {
      en: 'Value "{{value}}" must be a integer number.',
      es: 'Valor "{{value}}" debe ser número entero.'
    },

    // This is an special case. We can configure by properties only in this validator.
    isLength: {

      // We can configure a global message when the validator fails in this property.
      min: 'Mínimo valor: {{min}}.',

      // And we can configure by locale too.
      max: {
        en: 'Maximum value: {{max}}.',
        es: 'Máximo valor: {{max}}.'
      }
    }
  },

  fields: [{
    name: 'username',
    validators: {
      isAlphanumeric: 'en-GB',
      isLength: { min: 4, max: 16 },

      // If this fails, the default message will be used because the package
      // does not have a message for this validator by default
      isMongoId: true
    }
  }, {
    name: 'age',
    validators: {
      isInt: { max: 500 }
    }
  }]
};

const vv = vulcanval(settings);

let usernameValid = vv.validateField('username', map);
console.log(usernameValid); // 'Debe ser alfanumérico en local "en-GB".'

map.username = 'rp';
usernameValid = vv.validateField('username', map);
console.log(usernameValid); // 'Mínimo valor: 4.'

let ageValid = vv.validateField('age', map);
console.log(ageValid); // 'Valor "720" debe ser número entero.'

<static> validationEvents :String

Only client-side.

After first validation, what events to listen to re-validate fields.

Type:
  • String
Default Value:
  • 'input blur change'