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

Core: Add support for defining a global normalizer #1905

Merged
merged 1 commit into from Dec 25, 2016

Conversation

Arkni
Copy link
Member

@Arkni Arkni commented Dec 11, 2016

This PR added support for using a global normalizer for all elements of the form, which will run for all elements if it's present in the top level (the same level as rules) without affecting the current behaviour, that way you can transform the values of a set of elements without attaching the same normalizer to the aforementioned elements, and you can override it on element level by specifying a normalizer for the specific element that you want to transform differently.

In pseudo code, this will look like:

$("#myForm").validate({
  normalizer: function(value) {
    // Trim the value of every element
    return $.trim(value);
  },
  rules: {
    username: {
      required: true,
      // Here, we override the global normalizer
      normalizer: function(value) {
        value = value.replace("something", "new thing");
        return $.trim(value);
      }
    }
  }
});

@staabm
Copy link
Member

staabm commented Dec 25, 2016

Thx.🎄

@Arkni Arkni deleted the global-normalizer branch December 25, 2016 17:31
@cheonhyangzhang
Copy link

Hi @Arkni
when you have defined global normalizer and specific normalizer, will they both be executed? or only one of them is executed? If both is executed, what's the order of execution?

@Arkni
Copy link
Member Author

Arkni commented Feb 1, 2017

Only one of them is executed which is the specific one.
What we do here is overriding the global normalizer in case a specific one exist. So in the following example, only usernameNormalizer will be executed for the username element and globalNormalizer will run for other fields:

$("#myForm").validate({
  // This will run for every element except for the ones that have their own normalizer.
  // In our case, this will not run for `username` element.
  normalizer: function globalNormalizer(value) {
    return $.trim(value);
  },
  rules: {
    username: {
      required: true,
      // Here, we override the global normalizer
      normalizer: function usernameNormalizer(value) {
        return value.toUpperCase();
      }
    },
    fullname: {
      required: true
    }
  }
});

@cheonhyangzhang
Copy link

@Arkni Got it.

Thanks for the explanation and the nice work.

Do you know about any schedule for the next release? Is next release going to have this feature? And if so when will that be ?

@Arkni
Copy link
Member Author

Arkni commented Feb 2, 2017

@cheonhyangzhang

Do you know about any schedule for the next release?

There still some issues to be fixed before the next release. So, maybe after fixing them, we will do a minor release.

Is next release going to have this feature?

Yes

And if so when will that be ?

Same as answer 1.

@cheonhyangzhang
Copy link

@Arkni
Cool! Thanks!

@reachmehar
Copy link

Nice one. Any ETA on this feature?
According to https://jqueryvalidation.org/normalizer/ it seems like both global and element specific normalizer might work but not yet released?

@Arkni
Copy link
Member Author

Arkni commented Jul 20, 2017

The new release was planned for the end of June but got postponed and the documentation is ahead of its time :)

We will see if we can prepare a release the next week!

//c @staabm

@reachmehar
Copy link

That's nice.. how to subscribe for release alerts ?

@Arkni
Copy link
Member Author

Arkni commented Jul 21, 2017

Subscribe to #2016

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

Successfully merging this pull request may close these issues.

None yet

4 participants