Link Details

Link 60045 thumbnail
User 111696 avatar

By bloid
via code.google.com
Published: Jan 06 2008 / 22:47

jQuery AOP is a very small plugin that adds AOP features to javascript. It allows to add advices (Before, After and Around) to any global or instance function.
  • 13
  • 0
  • 715
  • 219

Comments

Add your comment
User 202487 avatar

alex.objelean replied ago:

0 votes Vote down Vote up Reply

I found this plugin very useful. My concrete situation was: adding client-side validation to a form using IceFaces JSF implementation. Unfortunately, when using ice:commandButton inside a form, the onSubmit() function is not called on the form, and the rendered submit button overrides the onclick function, thus it seemed impossible to add my validation script on the rendered form. My solution was to add an around advice to the submit button, decorating the onclick function with the validation script:

var refButton = ...// get the submit button reference
$.aop.around( {target: refButton, method: 'onclick'},
function(invocation) {
var refForm = $(this).parents("form:first")[0]; //get the form reference
var isValid = ..//perform client side validation on the form
return isValid ?invocation.proceed() : false; //proceed if the validation succeeded.
}
);

I find this approach completely unobtrusive and elegant, when you cannot change the rendered markup in order to add some behavior.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (13)



Voters Against This Link (0)