Catfish
Catfish

Reputation: 19284

jquery plugin doesn't recognize calling parameters

I've created a plugin and I have my defaults set but when I change the parameters in the calling script, they are not reflected, the defaults are always taking precedence. What am i missing here?

calling script in my .html file

$('.inputBox').validate(function() {
    rounded: true
});

Stripped down plugin. Even though i'm setting rounded to true in the first snippet, it's always false when i log it to the console in firebug. Why is this?

(function($) {
    $.fn.validate = function(options) {

    var 
        defaults = {
            rounded: false
        },
    settings = $.extend({}, defaults, options);

        $(this).each(function(index) {
            if(settings.rounded) {
            $(this).addClass('roundedMsg'); 
        }
    }); 
    return this;
    };  
})(jQuery);

Upvotes: 0

Views: 81

Answers (1)

PetersenDidIt
PetersenDidIt

Reputation: 25620

You don't need to pass a function to the plugin, you need to pass an object:

$('.inputBox').validate({
    rounded: true
});

Upvotes: 2

Related Questions