0

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);

1 Answer 1

2

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

$('.inputBox').validate({
    rounded: true
});
Sign up to request clarification or add additional context in comments.

1 Comment

What he posted is only valid javascript because javascript supports labels. He created a label named "rounded" in a function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.