-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Description
I've looked at the new proposed forms specification and I believe there would be an alternative way of integrating error messages in custom form templates.
The following is way to heavy in my opinion:
<div *if="form.hasError('city', 'required')">Required</div>
It's great to have the flexibility to do the above, but in most cases I believe that something like the following could be appropriate:
<control-errors control="city" show="1"></control-errors>
However, that also means we need more control over the error messages generation. Simply adding details about the rules definitions as well as what went wrong for every broken rule would allow to build generic solutions that are quite flexible.
For instance, if we have a maxLength=10 rule that failed because the string was 15chars long, then the broken rule representation could be something like { type: 'maxLength', maxLength: 10, actualLength: 15 }.
Then we could configure messages using a provider such as:
$validationMessageProvider.registerMessageFor('maxLength', "too long by {actualLength - maxLength} character(s)")
Obviously, we would have to think more about what would be an appropriate standardized broken rule schema, especially if we wish to support combined rules as well (assuming the rest of the framework supports them). For example, a complexPassword rule composed of a specialChars rule and a minLength rule.