Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attributeDescription should be per-field, not per-validator #38

Closed
lolmaus opened this issue Sep 19, 2015 · 2 comments
Closed

attributeDescription should be per-field, not per-validator #38

lolmaus opened this issue Sep 19, 2015 · 2 comments

Comments

@lolmaus
Copy link

lolmaus commented Sep 19, 2015

It is burdensome to pass attributeDescription to every validator of a field:

const Validations = buildValidations({
  name: [
    validator('presence', {
      presence: true,
      attributeDescription: 'Course name (language)'
    }),
    validator('length', {
      min: 1,
      attributeDescription: 'Course name (language)'
    }),
    validator('no-whitespace-around', {
      attributeDescription: 'Course name (language)'
    })
  ]
});

It is obvious that conceptually attributeDescription is an entity that belongs to the whole field and should be shared among all validators.

I suggest the following API:

/**
 * Top level method that will ultimately return a mixin with all CP validations
 * @param  {Object} validations  Validation rules
 * @param  {Object} commonOptions  Options to be includd into every validator unless defined explicitly
 * @return {Ember.Mixin}
 */
export default function buildValidations(validations) {

which would drastically simplify the above example:

const Validations = buildValidations({
  name: [
    validator('presence', true),
    validator('length', { min: 1 }),
    validator('no-whitespace-around')
  ]
},
{
  attributeDescription: 'Course name (language)'
});
@offirgolan
Copy link
Collaborator

Thanks for the suggestion. I definitely had something like this in my head for future implementation. Ill take a look into this more when I have some time.

offirgolan pushed a commit that referenced this issue Sep 30, 2015
* Add buildOptions and processOptions hooks
* Default options for validators (#38)
* All options can be functions that are called right before validated
via processOptions
* Removed moment dependency (#30)
@offirgolan
Copy link
Collaborator

This will be available once we release 2.0! Thanks again for the suggestion 😄

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

No branches or pull requests

2 participants