bryntum / support

An issues-only repository for the Bryntum project management component suite which includes powerful Grid, Scheduler, Calendar, Kanban Task Board and Gantt chart components all built in pure JS / CSS / TypeScript
https://www.bryntum.com
54 stars 6 forks source link

Combo box does not clear unmatched initial value. #10285

Open bmblb opened 4 days ago

bmblb commented 4 days ago

Reported here: https://forum.bryntum.com/viewtopic.php?f=43&t=30944&p=157181#p157181

To reproduce use this combo box config:

tbar : {
        // type : 'gantttoolbar'
        items : {
            foo : {
                type      : 'combobox',
                items     : [{ id : 1, text : 'foo' }, { id : 2, text : 'bar' }],
                value     : 'baz',
                clearable : true
            }
        }
    }

When you click the clear toggle, first click does nothing. Second clears the input value

UPD: also smth to look at

When we set value which does not exist in the combo, only onChange is triggered. If a value from the store is selected both onChange and onSelect are triggered.

ExtAnimal commented 4 days ago

I think the fix in Combo.js is

    /**
     * Clears the value of this Field, and triggers the {@link #event-clear} event.
     */
    clear(event) {
        const
            me        = this,
            { value } = me;

        // input.value may be null. Custom input elements may have non-string values
        // and may be cleared to null
        if (value !== me.nullValue || me.input.value) {
            me.value = me._lastValue = me.nullValue;
            me.clearError();
            me.syncInvalid();

            // event will be present if called from the clearTrigger click
            me.trigger('clear', { event });
        }
    }

The issue was that the _lastValue property is supposed to be a temporary "placeholder" value which is returned as the field's value if an invalid, unmatched in the store value is set, or if a value has been set while an AjaxStore has not loaded.

It gets cleared upon arrival of a valid value.

Clearing the field is setting a valid value, so clear _lastValue there too, before clearing the value.