2

Trying to bind click confirmation with jQuery (to clean code in JSF page) I understand that onclick inline function (oamSubmitForm();) written by MyFaces is executed before jQuery click() event. Is possible to do jQuery click before instead?

jQuery(".commandButtonConfirmDelete").click(function() {
  var answer = confirm('Confirm Delete?');
  return answer;
});  

<h:commandLink styleClass="commandButtonConfirmDelete" />
<h:commandButton styleClass="commandButtonConfirmDelete" />  
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Mirco Attocchi
  • 776
  • 1
  • 7
  • 14

2 Answers2

2

You're best bet is to retrieve the inline click event, save it, delete it and overwrite it with your own function that does what you want to do and eventually calls the saved function that you deleted. I'd do something like this...

$(function() {
  var node = $('.commandButtonConfirmDelete').get(0),
      savedAction = node.onclick;

  //Remove the inline handler (we'll call it manually in our new handler)
  node.onclick = null;

  $(node).click(function() {
     //do something   

     //then call your inline action
     savedAction();
  });
});

See this fiddle - http://jsfiddle.net/C9HTp/1/

alert('bar') is set inline and alert('foo') is bound via .click(). However using the method described above, the alerts go in order of 'foo' then 'bar'.

Hope this helps!

John Strickler
  • 25,151
  • 4
  • 52
  • 68
0

If you can work with IDs, you can use client-ids for the click event.

jQuery("#formId:commandButtonConfirmDelete").click(function() { var answer = confirm('Confirm Delete?'); return answer; });
<h:commandButton id="commandButtonConfirmDelete" />

darkapple
  • 539
  • 1
  • 7
  • 19