ember-changeset-validations icon indicating copy to clipboard operation
ember-changeset-validations copied to clipboard

Feature Request: Public API for getDescriptionFor

Open lcpriest opened this issue 8 years ago • 2 comments

In my app, the propertyName for the input does not always map to the displayed label; this would be even more common in localised products.

For example:

<label for={{concat type "-" property}}>{{spanishProperty}}</label>
<input
  class="u-full-width"
  type={{type}}
  id={{concat type "-" property}}
  value={{get changeset property}}
  oninput={{action (mut (get changeset property)) value="target.value"}}
  onblur={{action validateProperty}}>
{{#if (get changeset.error property)}}
  <small>
  	<ul>
    	{{#each (get (get changeset.error property) "validation") as |message|}}
    		<li>{{message}}</li>
    	{{/each}}
    </ul>
  </small>
{{/if}}

While it is possible to change the messages hash per language, the hardcoded {description} just takes the propertyName and normalises it.

Would it be possible to allow the app/utils/messages.js file to be overridden, in order to allow more complex names for the {description} placeholder?

lcpriest avatar Apr 24 '17 02:04 lcpriest

Im just looking into custom validators, which got me thinking.

Wrap each provided validator you need, and before the buildMessage function is called you can intercept the message and provide your own language based one.

For example, 'isOne' maps to messages.js, so you could have 'isOneENG' , 'isOneFR' etc...

import buildMessage from 'ember-changeset-validations/utils/validation-errors'; // validators/custom.js export default function validateIsOne(options) { return (key, newValue, oldValue, changes, content) => { return newValue === 1 || buildMessage(key, 'isOne', newValue, options); } }

MatthewPringle avatar Apr 24 '17 15:04 MatthewPringle

I would very much like to see this as well. Not even for localization, but in many cases the propertyName doesnt normalize to something user friendly, such a foobarId foreign key type property.

billdami avatar Oct 17 '17 12:10 billdami