[article rbarticle] How to configure Object Record form sub

Posted by Mohammed Siraj on 16-Dec-2015 00:39

In Rollbase, for Record New/Edit/Status-Change/QuickCreate pages, user can configure 'onsbumit' event handler in

Object Definition -> Pages -> Edit Page -> Properties -> HTML Event Handlers section.

Additionally, with New UI (4.0.4) release, we have added client-side API options to acheive the same. Users can now also configure a script component on the page & leverage this API to attach form submit handlers.

Given below is a code snippet that demonstrates the same:

Attaching form submit handlers in New/Edit/Status-Change/Quick-Create pages:

<script>
try {

if (!rbf_isNewUI()) {
throw 'This Script is written specific to New UI Context';
}

var onFormSubmit = function (event) {
//submit handler...
if(console){
console.log("Form Validation Status: "+event.validationStatus);
}

//to prevent form submission
event.preventDefault();
};

rb.newui.util.addEventListener(rb.newui.util.customEvents.rbs_pageRender, function () {
//Get formContext instance for Edit Form in page
var formContext = rbf_getObjectRecordForm();
if (formContext) {
formContext.addSubmitHandler(onFormSubmit);
}
});

}
catch (err) {
if (console) {
console.log(err);
}
}

</script>

Note: Directly attaching form submit handlers on <form> elements or 'click' event handlers on Submit button in page is discouraged. This may interfere with Rollbase platform behavior & also have compatibility issues across releases. Additionally, handlers configured in this manner may also be incorrectly notified on form cancel.

All Replies

Posted by gmandujano on 15-Nov-2017 10:57

I'm having a bit of trouble with this -- I have a function in the Object > Page Properties > HTML Event Handlers > onsubmit() field.  This function is getting triggered when the user presses "Cancel" and "Save."  How do I prevent the function from being executed when the user presses "Cancel"?

Here's the function in onsubmit:

savePickUp(function() {

rbf_growlInfo("Testing", "onsubmit triggered");

});

where "savePickUp" is a function defined in a custom script on the page.

Posted by Mohammed Siraj on 15-Nov-2017 23:53

Yes, there is an issue here. Ideally form submit handlers should not be notified on form cancel.

We will resolve this in a forthcoming release. For a workaround, can you please review the following thread:

https://community.progress.com/community_groups/rollbase/f/25/t/21673

This thread is closed