I'm trying make a custom event PreSave and I need to do some asynchronous requests, because of this I always have to return false on PreSave and call the postback manually.

The problem is disable the event on submit button, to workaround this I've that remove onclick attribute, but I can't do without the button ID.

How can I get the ID from save button and datetime initial and final for the current form page?


Every eidt form has client form context object, that is called something like WPQ2FormCtx. This object has property SubmitButtonID, there ID of submit button is specified.

Keep in mind, this object name WPQ{x}FormCtx can be different if your master page does or does no have other web parts before the edit form web part. Best way to determine client form context object name would be to use CSR. Add JSLink to your web part and override OnPreRender(ctx) event. In this event you get render context ctx as parameter. This object has property FormUniqueId that holds form unique id value that usually is WPQ2 or similar.

Here is sample how to use CSR and use OnPrerender method https://code.msdn.microsoft.com/office/Client-side-rendering-code-b2eedf92


If you use your browsers dev tools and browse the source, you can find the ID of the button with the inspector functionality. I'd test this a bit after you implement to make sure the button ID isn't dynamic. I don't think it is, but I would double check just in case. In the event that it is, you can probably use jQuery to come up with a custom selector that lets you point at the button in a stable way. enter image description here

  • I already did this, the problem is that sometimes this code changes. And I don't know why.
    – Carlos
    Sep 24 '15 at 17:45
  • 1
    Try using a pseudo selector with jQuery: $("input[value='Save']")
    – CountZero
    Sep 24 '15 at 17:52
  • This is a good solution to apply on save button, but time field has no attribute title and the ids are so similar, changing just some numbers inside this long code.
    – Carlos
    Sep 24 '15 at 18:19
  • If you only have one field of type date/time, the parent element will have a unique class of "ms-dttimeinput". In combination with a pseudo selector, you can narrow it down to the hours and minutes "select" elements even further.
    – CountZero
    Sep 24 '15 at 18:27
  • Isn't only one, is initial and final date and time. I'm not finding a solution. Becoming depressed...
    – Carlos
    Sep 24 '15 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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