Confirmation popup for saving a record in Preview view

I have overridden handleSave() so that when a record is saved with Outcome status equal to 'appointment' and the 'Appointment Date' field is blank, user is prompted to Confirm or Cancel.  However, clicking on Cancel doesn't cancel the save.

Error: Uncaught TypeError: this.handleCancel() is not a function.

Is this related to the Preview view?

Also, depending on the user's choice, I would like to change the field 'ok_to_save_c' so that I can use a Process Definition to use different templates for bookings/appointments with and without appointment dates but I can't seem to change the field to match the choice due to the following.

1. When this.model.set() is used inside the confirmation alert:

Error: Uncaught TypeError: Cannot read properties of null (reading 'set')

2. When this.model.set() is used after the confirmation alert, the code following the prompt executes before the user makes the selection.

Any help would be appreciated.

Thanks,

Homin

({

extendsFrom: 'PreviewView',

initialize: function(options)

{

  this._super('initialize', [options]);

...........

},

handleSave: function() {

  this.model.set('ok_to_save_c', true);

  this.OKtoSave = true;
  var outcome = this.model.get('outcome_c');
  if(outcome == 'appointment')
  {
    var apptDate = this.model.get('preferred_appointment_c');
    if(apptDate == '')
    {
      app.alert.show('message-id', {
        level: 'confirmation',
        messages: 'Date was not entered for an Appointment/Booking. OK to save?',
        autoClose: false,
        onConfirm: function() {
          //this.model.set('ok_to_save_c', true); //Error: Uncaught TypeError: Cannot read properties of null (reading 'set')

          this.OKtoSave = true;
        },
        onCancel: function() {
          this.handleCancel(); // Error: Uncaught TypeError: this.handleCancel() is not a function
          //this.model.set('ok_to_save_c', false); //Error: Uncaught TypeError: Cannot read properties of null (reading 'set')
          this.OKtoSave = false;
        },
      });

      console.log('OKtoSave: ' + this.OKtoSave); // this executes before the confirmation alert is cleared and it always returns true
      if(this.OKtoSave)
        this.model.set('ok_to_save_c', true);
      else
        this.model.set('c', false);
    }

 }

},

Parents
  • I think it is due to "this" being null in the onConfirm function. Can you try doing the following:


    app.alert.show('message-id', {
            level: 'confirmation',
            messages: 'Date was not entered for an Appointment/Booking. OK to save?',
            autoClose: false,
            onConfirm: _.bind(function() {
              //this.model.set('ok_to_save_c', true); //Error: Uncaught TypeError: Cannot read properties of null (reading 'set')

              this.OKtoSave = true;
            }, this),
            onCancel: _.bind(function() {
              this.handleCancel(); // Error: Uncaught TypeError: this.handleCancel() is not a function
              //this.model.set('ok_to_save_c', false); //Error: Uncaught TypeError: Cannot read properties of null (reading 'set')
              this.OKtoSave = false;
            }, this),


    The bind will allow the callback function to access the "this" function from the parent context.

Reply
  • I think it is due to "this" being null in the onConfirm function. Can you try doing the following:


    app.alert.show('message-id', {
            level: 'confirmation',
            messages: 'Date was not entered for an Appointment/Booking. OK to save?',
            autoClose: false,
            onConfirm: _.bind(function() {
              //this.model.set('ok_to_save_c', true); //Error: Uncaught TypeError: Cannot read properties of null (reading 'set')

              this.OKtoSave = true;
            }, this),
            onCancel: _.bind(function() {
              this.handleCancel(); // Error: Uncaught TypeError: this.handleCancel() is not a function
              //this.model.set('ok_to_save_c', false); //Error: Uncaught TypeError: Cannot read properties of null (reading 'set')
              this.OKtoSave = false;
            }, this),


    The bind will allow the callback function to access the "this" function from the parent context.

Children
No Data