aurelia / validatejs

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

How to handle properties with different labels #66

Closed jadrake75 closed 8 years ago

jadrake75 commented 8 years ago

If you model has a property like "price" but this is rendering in the UI using a label like "Total Purchase" when it validates you will get messages referring to "Price". Now I know I can set message, but his seems to only be the message part "after" the variable. ie. if I set a message like "Total purchase must be a number greater than 0" I will get "Price Total purhase must be a number greater than 0"

purchase-dialog

I am assuming this is a simple option I am missing but I have not located anything.

apawsey commented 8 years ago

This is a validate.js option. By default it uses the name of the property. If you pass a config for that property, including a message, prefix the message with ^ to avoid it adding the property name.

eg:

new Validator(this)
    .ensure('price')
        .required({message: '^Total purchase doesn't look like a number!  Think you ought to check that buddy'});
jadrake75 commented 8 years ago

ah... yes... I guess if I put on my regexy hat that makes sense. I saw that in a few examples but it didn't click. ok.... lets close it out!