Skip to content

Conversation

matthopson
Copy link
Contributor

Example usage:

Method 1

Define your validation options in your controller:

controller.validateFirstName =
     required:
       value:true
       errorMessage: "Woah, woah! You forgot to tell me your first name, bro."
     minLength:
       value: 5
       errorMessage: "Say, bro. This field requires at least five characters."

And in your HTML:

<input type="text" name="FirstName" validate-text="validateFirstName">

Method 2

You can define some validations right in your HTML like so:

<input type="text" name="FirstName" validate-text="required:true -e 'Woah, woah! You forgot to tell me your first name, bro.'|minLength:5">

In this example, validation options are added as key:value and separated with |. To add an error message to a validation option use the -e flag in the value portion of the option like so: key:value -e 'Your error message'

Validation Types

Validation types can be created and defined using validate-VALIDATION_TYPE="VALIDATION_OPTIONS"

If a validation type is used but doesn't have any rules defined for it, it will pass validation but will throw a warning in the console.

Moving Forward

Would like to be able to define validation rules on the application level instead of within the validation script - some basic validation options could remain baked in, but for the most part I think it would be nice if you had to explicitly define your validation rules to suit your app.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work for forms that have portions inside of partials, perhaps several deep, or forms that have repeating sections which create controllers for that section.

We'll need to have a binding at the form level that will create the validation object on that controller. Here we can throw an error if the validation object doesn't exist indicating that it must be created using bind-validate or whatever we call the aggregating binding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants