mercredi 20 janvier 2016

Dynamically setting validations object in Ember- ember-validations

Using dockyard/ember-validationsThe default way of setting validation rule is like below.

var Controller = Em.Controller.extend( 

{

validations:  {
'model.firstName':
  {presence:
    {message: 'First Name is a required field.'}
  },
'model.lastName':
  {presence:
    {message: 'Last Name is a required field.'}
  }  
},

..

}

But I want to choose this validations object based on a condition, I choosen as a function property like below.

var Controller = Em.Controller.extend( 

{

validations: function() {
if(somecondition)
{
return{ 'model.firstName':
  {presence:
    {message: 'First Name is a required field.'}
  },
'model.lastName':
  {presence:
    {message: 'Last Name is a required field.'}
  }  
}
else
{..}
 }

 }.property(),

..

}

But when I am converting this as a function ember-validations library is not working as expected. How can i mitigate this situation?




Aucun commentaire:

Enregistrer un commentaire