admin管理员组文章数量:1356271
I'm trying to override a method inside a jquery widget. The method can be found on line 122 at .js
Id like to alter the html output on line 141
I've tried adding the following to my custom js class without success. If anybody could explain how to do this, id greatly appreciate it.
(function($) {
$.widget( "ui.tapestryFieldEventManager", {
showValidationMessage : function(message) {
var field = this.element;
var form = field.closest('form');
this.options.validationError = true;
form.formEventManager("setValidationError", true);
field.addClass("t-error");
this.getLabel() && this.getLabel().addClass("t-error");
var icon = this.getIcon();
if (icon) icon.show();
alert("here");
var id = field.attr('id')+"\\:errorpopup";
if($("#"+id).size()==0) //if the errorpopup isn't on the page yet, we create it
field.after("<div id='"+field.attr('id')+":errorpopup' class='tjq-error-popup test'/>");
Tapestry.ErrorPopup.show($("#"+id),"<span>"+message+"</span>");
}
});
})(jQuery);
I'm trying to override a method inside a jquery widget. The method can be found on line 122 at https://github./got5/tapestry5-jquery/blob/master/src/main/resources/org/got5/tapestry5/jquery/validation.js
Id like to alter the html output on line 141
I've tried adding the following to my custom js class without success. If anybody could explain how to do this, id greatly appreciate it.
(function($) {
$.widget( "ui.tapestryFieldEventManager", {
showValidationMessage : function(message) {
var field = this.element;
var form = field.closest('form');
this.options.validationError = true;
form.formEventManager("setValidationError", true);
field.addClass("t-error");
this.getLabel() && this.getLabel().addClass("t-error");
var icon = this.getIcon();
if (icon) icon.show();
alert("here");
var id = field.attr('id')+"\\:errorpopup";
if($("#"+id).size()==0) //if the errorpopup isn't on the page yet, we create it
field.after("<div id='"+field.attr('id')+":errorpopup' class='tjq-error-popup test'/>");
Tapestry.ErrorPopup.show($("#"+id),"<span>"+message+"</span>");
}
});
})(jQuery);
Share
Improve this question
asked Jun 15, 2012 at 14:57
Code JunkieCode Junkie
7,78827 gold badges86 silver badges147 bronze badges
1 Answer
Reset to default 9You have to override it on the prototype.
var oldMethod = $.ui.tapestryFieldEventManager.prototype.showValidationMessage;
$.ui.tapestryFieldEventManager.prototype.showValidationMessage = function (message) {
// do your stuff here
alert("worky");
// apply old method
oldMethod.apply(this,arguments);
};
Of course, you could skip applying the old method if your new method does everything that the old method did.
本文标签: javascriptOverride method inside jquery widgetStack Overflow
版权声明:本文标题:javascript - Override method inside jquery widget - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743965782a2569859.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论