Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Cancelling saving of form in preSave event

Avatar

Level 1

I am performing cross field validation before saving the form (in preSave event) and want to cancel the saving of the form. I have tried returning 0, false, but nothing seems to work and the form is saved anyway. How can I cancel the saving of the form?

4 Replies

Avatar

Level 10

Can you explain what you meant by Saving of the form.. Are you using File -> Save (or) placing a button on the form and on the click of it you atre trying to save the form?

Thanks

Srini

Avatar

Level 1

I mean, when I click on the Small Disk or File->Save or even on the File->saveAs, I would like to block any kind of saving of the form until all my validations have been sucessfully met. I will also want to do it for any Print functionality.

Avatar

Level 3

You can't cancel printing or saving.


Avatar

Level 4

One thing you could try, and this may not be remotely close to what you want, but on the preSave/Print events, you can do validation for required fields and such, and if they are not completely filled in, change the content area to display a message like "you tried saving an incomplete form.  Please fill out the form again".  Then if they print the form, that's all they see instead of the content.

Edit: I actually did this on a form...if it wasn't showing a barcode, I set the page content to "invisible" and on the postPrint (and alerted the user), I turned it "visible" again so they could fill out the form or change what they needed to.