0

I tried my solution in this forum for five days and found some similar situations, but still could not solve my problem.

1- I am using pure jsf
2- I need before deleting a row from my table, there is a confirmation, a modal (I'm trying to use the smartNotifications)
3 - I can call the javascript function and suspend the delete action, but after clicking the button "Yes, I want to delete the record" does not continue the process of erasing the record, stands in the same place.

Follow my example below

Java code

<h:form id="form1">
    <h:datatable id="tab1">
      <h:column id="column1">
        <f:facet name="header">User</f:facet>
        <h:outputText rendered="#{bean.User}"></h:outputText>
      </h:column>
      <h:column id="column2">
        <h:commandlink onclick="delete();" action="#{bean.deleteUser}" />
      </h:column>
    </h:datatable>
</h:form>

Javascript:

function delete(e) {
  $.SmartMessageBox({
    title: "Are you Sure?",
    content: "This action can not be undone",
    buttons: '[Yes][No]'
 }, function (ButtonPressed) {
    if (ButtonPressed === "Yes") {
        return true;
    }
    if (ButtonPressed === "No") {
        return false;
    }
});
e.preventDefault();

}

Please help me

1 Answers1

0

They way your code is run e.preventDefault() get's called in any case. What you want (I'm assuming) is to put e.preventDefault(); in the if Button === No Section

function delete(e) {
  $.SmartMessageBox({
    title: "Are you Sure?",
    content: "This action can not be undone",
    buttons: '[Yes][No]'
 }, function (ButtonPressed) {
    if (ButtonPressed === "Yes") {
        return true;
    }
    if (ButtonPressed === "No") {
        e.preventDefault();
    }
});
}
Kevin Grabher
  • 399
  • 1
  • 4
  • 18
  • Hello Kevin, thanks... Really e.preventDefault () function; appears to be in the wrong place, but when I put below the if, the execution is not stopping now ... now the confirmation screen appears but the record is deleted from the table. I think if I could put the e.preventDefault before the two ifs, would work, but I don't know how do this ... – fsantannadi Mar 23 '15 at 20:15
  • Perhaps put the e.preventDefault at the Beginning of the function so it's stopped either way (or remove the action from your java-code if that's an option) and trigger the action in the if(button=yes) – Kevin Grabher Mar 24 '15 at 13:44