Lua.vm.js-Samples

 Form validation

Summary

The goal of this sample is to show how we can use a lua table to encapsulate all the ui logic.

Extract :

local ui = {
  formClass = "to-validate",
  formElement,
  fields = {
    pseudo = {
      id = "pseudo",
      alias = "Pseudo",
      rules = {
        isRequired
      },
      element,
      errorElement
    },
    email = {
      id = "email",
      alias = "Email",
      rules = {
        isRequired,
        isEmail
      },
      element,
      errorElement
    },
    password = {
      id = "password",
      alias = "Password",
      rules = {
        isRequired
      },
      element,
      errorElement
    },
    password_conf = {
      id = "password_conf",
      alias = "Password confirmation",
      equalTo = "password",
      rules = {
        isRequired,
        isEqual
      },
      element,
      errorElement
    }
  }
}

This table contains a list of fields where all the logic of validation is.

Each field consist of:

The fields can also have some extra keys like:

Go to sample