cancel radioenum edit

I want to alter a radioenum controller so that it asks for confirmation when toggling between two values.

The radioenum has values "None", "Primary" and "Duplicate"

when changing from Primary to either "None" or "Primary" to  "Duplicate" it needs to open a confirmation alert, and if the user Cancels the field needs to go back to detail view status (as opposed to its edit status) with the original value of "Primary" as if it was never edited.

The problem is I can't figure out how to cancel the edit from the radioenum field controller (I want this to work in record but also list view edits).

Ideally the cancel would also cancel the record edit or editable list edit if that was the only field that was changed.  

Any thoughts?
thanks

FrancescaS

  • I believe that the best choice is to create a custom radioenum field (which extends the default one) for this purpose and declare this field on both views record.php and list.php.

    In the initialize method you can add a code like that:

    this.model.on("change:" + this.name, this.warnUser, this);

    And the method warnUser may have a code like that:

    warnUser: function(evt, value) {
     if(_.isUndefined(this.model.changed.created_by)) {
     // implement a combination of methods beforeViewChange and warnUnsavedChanges from plugin Editable
     // include/javascript/sugar7/plugins/Editable.js
     }
    },

    This way the event will be triggered on both recordview and listview.

    Good luck

    André Lopes
    Lampada Global
    Skype: andre.lampada