javascript - How to validate input parameters of a jQuery widget factory before initialize the widget with them? -
is there way validate input parameters of jquery widget factory
before initialize widget options
them?
i want prevent incorrect parameters , use default options instead of them.
something this:
$.widget( "custom.colorit", { options: { color: 'red' }, _create: function(opts) { //<< opts not working here var validatedoptions == this._validateoptions(opts); // merge default options validated options this.options= $.extend(this.options,validatedoptions); this.element.text( this.options.color ); }, _validateoptions: function( opts ) { if(opts.color =='green') opts.color='blue'; if(opts.color =='black') opts.color= undefined; return opts; } });
Comments
Post a Comment