AnsweredAssumed Answered

Is it possible to modify EnumField to support deprecated values?

Question asked by Maritn Hawes on Aug 24, 2017
Latest reply on Aug 25, 2017 by Maritn Hawes

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?

Outcomes