Code Monkey home page Code Monkey logo

Comments (3)

joecwallace avatar joecwallace commented on May 18, 2024

I think this may be beyond the scope of this plugin. I understand the use case and appreciate the suggestion, but I think I'm going to pass for now.

If you implement it sometime and are happy enough with the result to submit a pull request, I'll gladly reconsider. :)

from jquery-validator.

dkiestra avatar dkiestra commented on May 18, 2024

I see your point. However, only a minor modification will help me to achieve my goal. The "data-validations" validation attribute is hard-coded in the source code (line 44). All I need is that the validations attribute name can be specified in the method just like events, selector, preventDefault, etc. Something like this (showing diff output):

9a10

      validation_attr         : "validations",

38c39

< validate : function (selector, callback) {

      validate : function (selector, validation_attr, callback) {

44c45

< var validation_rules = $(this).data("validations"),

              var validation_rules = $(this).data(validation_attr),

322a324,327
if (!options.validation_attr) {
options.validation_attr = defaults.validation_attr;
}

327c332

< var valid = validations.validate(options.selector || this, options.callback);

                  var valid = validations.validate(options.selector || this, options.validation_attr, options.callback);

Then my code would be as follows:

$.fn.errors = function (method) {
method.validation_attr = 'errors';
return $.fn.validator.call(this, method);
};

$.fn.warnings = function (method) {
method.validation_attr = 'warnings';
return $.fn.validator.call(this, method);
};

$('myform').errors({
events : 'submit',
selector : 'input[type!=submit], select, textarea',
preventDefaultIfInvalid : true,
callback : function(elem, valid) {
if (!valid) {
$(elem).addClass('error');
} else {
$(elem).removeClass('error');
}
}
});

$('myform').warnings({
events : 'blur change',
selector : 'input[type!=submit], select, textarea',
callback : function(elem, valid) {
if (!valid) {
$(elem).addClass('warning');
} else {
$(elem).removeClass('warning');
}
}
});

from jquery-validator.

joecwallace avatar joecwallace commented on May 18, 2024

Sold. I'll try to add this as I work on tests.

from jquery-validator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.