preventing the form from saving if the URL is invalid. This all works great in the main PowerApps form:
function validateURL() { var fieldVal = Xrm.Page.getAttribute(/xx_url/).getValue(); var urlPattern = /^https?://////[^//s///$?#]+//.[^//s]*$/; if (urlPattern.test(fieldVal)) { // Valid URL Xrm.Page.ui.clearFormNotification(/urlValidation/); return true; // Allow the form to save } else { // Invalid URL Xrm.Page.ui.setFormNotification(/Invalid URL!/, /ERROR/, /urlValidation/); return false; // Prevent the form from saving }}function onSavePreventInvalidURL() { if (!validateURL()) { Xrm.Page.data.entity.addOnSave(validateCancel); }}function validateCancel(executionContext) { var saveEvent = executionContext.getEventArgs(); saveEvent.preventDefault(); // Cancel the form save action}// Register onSavePreventInvalidURL as a handler for the /OnSave/ eventXrm.Page.data.entity.addOnSave(onSavePreventInvalidURL);
But when I apply the same code to the Quick Create form for the same
table in the same way, the code works for valid URLs but not for invalid
URLs:
- An error is displayed (correctly)
- The form does not save (correctly)
- When the URL is corrected, the Error dissapears (correctly)
- But the form will not save (incorrectly)
One suggestion was that the Quick Create form may use /states/ differently
to the main form but I really don't know what that means or how it may
affect a fairly simple bit of JavaScript which is working well on the
main form.
I'm relatively new to this so don't know what I am missing. Any ideas?