none
How do I cancel the Save button functionality from Javascript in PWA 2010 timesheet page.? RRS feed

  • Question

  • Hi all,

    I have to cancel the save button's original event to be ignored through the javascript.

    Here is the scenario:

    I have to cancel the save event in PWA 2010 timesheet page, when particular custom validation fails.

    I have the code which does the validation in javascript and returns the true/false for the validation.

    Now the thing is , I want to cancel the Save event when validation fails.

    I tried returning the 'false', but did not work......

    In 2007, we had used something like...

    var save = LocateElementByTagID('input', 'idSaveBtn');
    var oldSave = save.onclick;
    
    // Replacement Save handler
    function TimeSheetSaveOnClick() {
        var valid = CustomValidation();
        if (!valid)
            window.event.returnValue = false;
        else oldSave();
        return;
    }
    
    

     

    Since the way of handling the button is moved to Ribbon, is it possible to do the same thing in 2010?

    Please let me know if there is a way.... or if you had already done similar to this...

    please ask me if there is more details required....

    Thanks...

     


    Muniappan
    Monday, December 26, 2011 9:10 AM

Answers

  • Actually there was no solution which works for this requirement. So we are handling the scenario differently now. :)

    Muniappan

    • Marked as answer by Muniappan S Friday, June 29, 2012 11:17 AM
    Friday, June 29, 2012 11:17 AM

All replies

  • Hi,

    You could possibly look at redefining the Save button command in the ribbon to execute your custom save action. The problem will be getting your custom save action to then call the out of the box save action. I have experimented around using Page Components to do this but not had a lot of luck, but understand that's the way to do it.

    Hope this gives you an idea.

     


    Alex Burton
    www.epmsource.com | Twitter
    Project Server TechCenter | Project Developer Center | Project Server Help | Project Product Page
    Monday, December 26, 2011 9:38 PM
    Moderator
  • There are a couple of ways to achieve the desired functionality. Firstly you can hook on the server the OnSaving event and cancel the action if your custom valdiation fails. This path ensures that your validation is called whenever the Save occurs, but it lacks the ability to report the validation errors to the end user. As fas as I understand it is the only fully supported way - you will see in a minute why.

    Secondly you can create as suggested your own save button. The challenge there is that you very likely do want te reuse the existing Save functionality associated with the out-of-the-box button. This requires some tricky interception, and therefore is likely not the intended way to expand functionality. Furthermore you should think about your validation itself. On which data do you wish to base the validation? Notice that the data present in the grid is not as easy to read as the contents of a dataset.

    That said, you may wish to check into the option to extend the grid to do the custom validation at an earlier stage. It is for example possible to generate a row error on certain conditions, and enforce the correction before any save can be called. If this is a suitable path for you is of course dependent on your data required for validation.

    Other options? I would be very interested to hear about it?

    Jan


    Jan Cirpka
    Tuesday, January 3, 2012 1:35 PM
  • Actually there was no solution which works for this requirement. So we are handling the scenario differently now. :)

    Muniappan

    • Marked as answer by Muniappan S Friday, June 29, 2012 11:17 AM
    Friday, June 29, 2012 11:17 AM
  • Hi Muniappan

    I also want to cancel the original save button of PDP page for My Task Page . Can you let me know what approach you are using to cancel the save event when some validation fails.

    Thursday, September 3, 2015 12:17 PM
  • Hi Supriya,

    The approach we used was updating the Product javascript file, which is not recommended by microsoft.(because there is a possiblity that patches will replace/overwrite thes files.)

    We had used this approach since customer was ready to take this risk.

    there will be some javascript file associated to every page that holds event handlers. you could use the debug file to find out the right event handler.

    hope this helps. 


    Muniappan

    Tuesday, September 8, 2015 4:28 AM