Is it possible to modify EnumField to support deprecated values?

Hello,

I have a drop down field which id like to make one of the list values available to view on existing records, but no longer selectable when a record is edited or a new record is created. 

My current plan is to modify the javascript to remove any list items which end with "DEPRECATED" before the selection list is rendered. See code below for what i've attempted so far, it doesn't seem to work.....

Path: custom/clients/base/fields/enum/enum.js

({
    extendsFrom: 'EnumField',

    initialize: function() {
        this._super('initialize', arguments);
    },

    // override load enums to deprecated items
    loadEnumOptions: function(fetch, callback) {
        this._super('loadEnumOptions', fetch, callback);

        var itemKeys = _.keys(this.items);
        var itemValues = _.values(this.items);
        var itemsToRemove = [];

        for (var i = 0; i < itemValues.length; i++) {
            if (itemValues[i].endsWith("DEPRECATED")) {
                itemsToRemove.push(itemKeys[i]);
            }
        }

        for (var i = 0; i < itemsToRemove.length; i++) {
            delete this.items[itemsToRemove[i]];
        }
    }
})

Is this easily possible and has anybody attempted this before?

  • I have legacy values, the same as you deprecated.

    In the Dropdown definition I added (legacy) to the right hand side (the user visible value).

    I then remove the values from the selection list in Create, but not in Record (removing them in record would cause them not to display). It's only a partial solution as the user could save, then edit just the academic subtype and set it to a legacy value, but by making them think about it some more I may avoid someone accidentally assigning a legacy value.

    ({
       extendsFrom: 'CreateView',
       initialize: function(options){
          this._super('initialize', [options]);
          this.hideLegacyValues();
       },
       hideLegacyValues: function(){
         // hide legacy items from academic_subtype
         var academic_subtype_list = app.lang.getAppListStrings('academic_subtype_list_DD');
         Object.keys(academic_subtype_list).forEach(function(key) {
            var check = academic_subtype_list[key].match(/legacy/);
            if(academic_subtype_list[key].match(/legacy/)){
               delete academic_subtype_list[key];
            }
         });
         this.model.fields['academic_subtype_c'].options = academic_subtype_list;
         // hide legacy items from acadmic subtype
         var academic_subtype = app.lang.getAppListStrings('academic_subtype_list_DD');
       },
       _dispose: function() {
         this._super('_dispose');
       },
    })

    Should you feel so inclined, upvote this Idea: Have a way to mark dropdown values as legacy 

    You could also add an on-change event in record view that checks the value for the substring "legacy" in my case, "deprecated" in yours, and alert the user giving them a chance to verify the value before saving.

    HTH

    FrancescaS

  • Thanks Francesca. This at least prevents the users from accidentally selecting a value they shouldn't when creating which is a big help.