0

I have a simple modal popup dialog launched on the "register" button of a "new element" form :

$( "#ctl00_m_g_9ff78e92_ed40_4212_ae0f_44b787664fa8_ctl00_toolBarTbl_RightRptControls_ctl00_ctl00_diidIOSaveItem" ).click(function() {


            if (confirm("Confirmez-vous ce choix de réforme ? : ")) {

             }
             else {
                 return false;
             }


    });

})

The dialog is launched but the "Cancel" doesn't work: the element is created anyway.

I've tried different way of returning the false method but same problem each time.

EDIT

$(document).ready(function(){

$( "#ctl00_m_g_9ff78e92_ed40_4212_ae0f_44b787664fa8_ctl00_toolBarTbl_RightRptControls_ctl00_ctl00_diidIOSaveItem" ).click(function() {


        function PreSaveAction() {   
           if (confirm("Confirmez-vous ce choix de réforme ? : ")) {
                return true;
           }
           else {
                return false;
           }
        }
         //OpenConfigurationDialog("Confirmez-vous ce choix de réforme ?");


        PreSaveAction();


    });

})
4
  • Is ctl00_m_g_9ff78e92_ed40_4212_ae0f_44b787664fa8_ctl00_toolBarTbl_RightRptControls_ctl00_ctl00_diidIOSaveItem the save button? Or is it a custom button?
    – Erin L
    Commented Apr 21, 2016 at 13:34
  • the save button
    – Jey10
    Commented Apr 21, 2016 at 13:57
  • 1
    Then you just need to delete all of your javascript, and replace it with JayHell's code.
    – Erin L
    Commented Apr 21, 2016 at 14:24
  • Ok thanks his answer is good but thanks for explanation
    – Jey10
    Commented Apr 21, 2016 at 14:30

1 Answer 1

2

Override the PreSaveAction in order to cancel the save.

    function PreSaveAction() {   
       if (confirm("Confirmez-vous ce choix de réforme ? : ")) {
            return true;
       }
       else {
            return false;
       }
    }
5
  • thanks but doing like that (see my edited question) it doesn't work
    – Jey10
    Commented Apr 21, 2016 at 12:28
  • 1
    It's not necessary to wrap it in jQuery or bind it to any button... if the function is in the page, upon the Save action it will get fired.
    – JayHell
    Commented Apr 21, 2016 at 12:32
  • sorry I'm not very good in jquery neither sharepoint for the moment. Can you explain me what I could do better and how?
    – Jey10
    Commented Apr 21, 2016 at 12:34
  • you could simply put that code into a JavaScript file, then edit the "NewForm" webpart to add the link for JS Link (Miscellaneous section | JS Link : ~sitecollection/pathtofile/file.js)
    – JayHell
    Commented Apr 21, 2016 at 13:21
  • I just replace all and put it directly in the html Thanks
    – Jey10
    Commented Apr 21, 2016 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.