Illimar Mattus

Dynamic dropdown values are not saving in database

Discussion created by Illimar Mattus on Apr 26, 2017
Latest reply on Apr 29, 2017 by Editha Kuske

I successfully fill a dropdown with values from database. I correctly see the values , but when i save them, nothing is saved in the database, and i get a success saving.
Below is the extend file of enum.js that i created. Could you please help me to make a success saving ?

 

({
    extendsFrom: 'EnumField',
    initialize: function(opts){
        this._super('initialize',[opts]);
        if (this.view.action !== 'filter-rows'){
            this._initEvents();
        }
    },
    _initEvents: function(){
        this._loadTeamsDropdownField();
    },

    _loadTeamsDropdownField: function() {
        if(this.name == 'reassign_to_team_c'){
            this.on('render', this.loadOptions, this);
        }
    },
    //define the on.change event for the case descriptor so we hsve a way to call it

    loadOptions: function(){

        var self = this;
        var r = {};
        if(this.name  == 'reassign_to_team_c'){

                App.api.call('get', App.api.buildURL('GetTeams/'), null, {
                    success: function (data) {

                        if (_.isObject(data)) {
                            _.each(data.results, function (element, index) {

                                r[index] = element;

                            });
                            self.items = r;
                            self._render();
                        }
                    }});

        }
    },

    unformat: function(value) {
        console.log('unformat'+value);

        console.log('unformat items'+JSON.stringify(this.items));
        if (this.def.isMultiSelect && _.isArray(value)) {
            console.log('mallin');
            var possibleKeys = _.keys(this.items);
            if (!this.def.ordered) {
                // if it's not ordered, i.e. sortable, force order
                value = _.intersection(possibleKeys, value);
            } else {
                // no need to force order, just keep valid keys
                value = _.intersection(value, possibleKeys);
            }
            return value;
        }

        if (this.def.isMultiSelect && _.isNull(value)) {
            return []// Returning value that is null equivalent to server.  Backbone.js won't sync attributes with null values.
        } else {
            return value;
        }
    },
})

Outcomes