aurelia / validatejs

Enables expressive validation using decorators and/or a fluent API.
MIT License
22 stars 23 forks source link

support binding expression, converters, etc in validation message templates #90

Closed taz closed 8 years ago

taz commented 8 years ago

Continuing on from Issue #82

I think it would be useful if error messages could access properties and functions in the model the form element is a part of.

I also think, that because this may require some sort of composition of the string/element, that it should enabled via a config flag on the rule and default to false.

Something like this:

  @email({message: '^Nope! ${email_c & oneTime} is not a valid address <a click.delegate="showValid()">Help</a>', compose: true})
  email = '';

Example here: (particularly the "email constant" field).

https://gist.run/?id=bc6bf040204b1e80e13ba57f8244cd58


An alternative idea is to allow messages to be handled completely in the template instead of using a renderer. (or a mixture of both potentially if you're adding classes/icons for say bootstrap and need access to the parent form-group).

ie:

<div class="form-group">
    <label for="email"> ... </label>
    <input value.bind="email & validate">
    <validation-messages>
       <message for="required" i18n="REQUIRED_FIELD"></message>
       <message for="filter">The value '${email | oneTime}' is not valid</message>
    </validation-messages>
</div>
jdanyow commented 8 years ago

implemented!