inconsistency in handling of store null record caption

LabKey Support Forum (Inactive)
inconsistency in handling of store null record caption Ben Bimber  2010-09-07 08:01
Status: Closed
 
LABKEY.ext.FormHelper.getFieldEditor is designed to interpret metadata and return a correctly configured Ext component. When that component is a combobox, there's code that inserts a blank record into the select menu, which is needed b/c otherwise the user could not actively choose null on the select menu. the caption of the null record currently defaults to '[none]'. there is a param which should allow a custom nullCaption, but this is not working. it's the result of an inconsistency between LABKEY.ext.FormHelper.getLookupStore and LABKEY.ext.Store.

In LABKEY.ext.FormHelper.getLookupStore, the following code exists starting at FormPanel.js line 528, which adds :

            if (!c.required)
            {
                config.nullRecord = {
                    displayColumn: c.lookup.displayColumn,
                    nullCaption: c.lookupNullCaption || "[none]"
                };
            }
            config.autoLoad = true;
            store = new LABKEY.ext.Store(config);

When creating the field, if you specify a lookupNullCaption, you should be able to override the default value of '[none]'. LABKEY.ext.FormHelper.getLookupStore attempts to do this above by supporting lookupNullCaption (see above). It then called LABKEY.ext.Store to actually create the store. Unfortunately, this is the code from LABKEY.ext.Store, line 600:

        if(this.nullRecord)
        {
            //create an extra record with a blank id column
            //and the null caption in the display column
            var data = {};
            data[this.reader.meta.id] = "";
            data[this.nullRecord.displayColumn] = this.nullCaption || "[none]";

so LABKEY.ext.Store is expecting this.nullCaption, but is being given this.nullRecord.nullCaption. the simplest fix is to change Store.js line 606 to:

data[this.nullRecord.displayColumn] = this.nullRecord.nullCaption || "[none]";

The above is the least intrusive fix to make this work. It seems like the proper solution might be for LABKEY.ext.FormHelper.getLookupStore to blindly pass the config options into LABKEY.ext.Store and let that code deal with setting t he proper caption, rather than doing essentially the same thing twice.

In addition to LABKEY.ext.FormHelper.getLookupStore, the following also do essentially the same thing:
LABKEY.ext.Store.getLookupStore
LABKEY.Utils.createExtStore

The same could be applied to them as well.