fulcrumapp / fulcrum-expressions

Fulcrum expressions engine
http://developer.fulcrumapp.com/expressions/intro/
5 stars 0 forks source link

Add support for stopping the save operation and presenting warnings #60

Closed zhm closed 1 year ago

zhm commented 1 year ago

What?

Adds support for stopping the save operation inside save-record and save-repeatable to be able to perform async tasks like MESSAGEBOX() and REQUEST() and conditionally SAVE() the record at a later point.

The new API consists of PREVENTDEFAULT() and SAVE() used together inside save-record:

ON('save-record', (event) => {
  // prevent the save from happening
  PREVENTDEFAULT();

  const messageParams = {
    title: 'Confirm',
    message: 'You have selected a critical safety violation. Are you sure?',
    buttons: ['Yes', 'No']
  };

  // start async message box, or any async operation like REQUEST()
  MESSAGEBOX(messageParams, (result) => {
    if (result.value === 'Yes') {
      // save the record now
      SAVE();
    }
  });
});

Why?

It's not possible to present custom warning messages and allow the user to continue. For example, if a user entered a severe defect on an inspection that might cost $1000's to replace, the customer might want to present a confirmation warning on save asking the user if they're sure they meant to enter that.

Testing

Add the above snippet to any form.