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

[Validation] Add ability to add a rule to a field after initializing validation #4267

Closed
jemarlin opened this issue Jul 11, 2016 · 1 comment
Milestone

Comments

@jemarlin
Copy link

jemarlin commented Jul 11, 2016

We had need in our project to conditionally add form validation based on workflow steps. We added this method to form module.add:

validation: function ( $field, rule ) {

  var
    identifier = $field.attr( 'id' ) || $field.attr( 'name' ) || $field.attr( 'data-' + metadata.validate ),
    validator
  ;

  if ( !validation || !$field.length) {
      return false;
  }

  validator = validation[identifier];
  if ( !validator ) { // no rules exist for field, create an empty rule set
      validator = validation[identifier] = { 'identifier': identifier, 'rules': [] };
  }

  validator.rules.push( rule ); // add the rule

  return true;

  },

Which can be called like so $form.form( 'add validation', $field, { 'type': 'empty', 'prompt': 'This field must contain a value' } );

@jlukic jlukic added this to the 2.2.x milestone Jul 15, 2016
@jlukic jlukic modified the milestones: 2.2.8, 2.2.x, 2.2.9 Feb 21, 2017
@jlukic jlukic modified the milestones: 2.2.10, 2.2.11 Mar 28, 2017
jlukic added a commit that referenced this issue Jul 11, 2017
jlukic added a commit that referenced this issue Jul 11, 2017
@jlukic
Copy link
Member

jlukic commented Jul 11, 2017

I've added add field add rule add fields remove rule remove fields in next version, check release notes and above commits for details.

I've also added an example in next doc update.

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