Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Combobox forceSelection with bind problem

    Looks like we can't reproduce the issue or there's a problem in the test case provided.
  1. #1
    Sencha Premium Member yorl1n's Avatar
    Join Date
    Mar 2015
    Location
    Germany
    Posts
    294

    Default Combobox forceSelection with bind problem

    Hi all,
    here is a fiddle with the problem. Try to make some change in combo, for example remove the last letter. As a result the combo box's value clears. So when combo is configured with forceSelection: true and value is binded, trying to make changes in combo clears value.

  2. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    Ok, but you've said it must have a selection. So when you start typing and nothing matches, the value of the combo becomes null. Sounds like you want to bind to the selection.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  3. #3
    Sencha Premium Member yorl1n's Avatar
    Join Date
    Mar 2015
    Location
    Germany
    Posts
    294

    Default

    I just want it works proper, in the way it works with normal(not binded value).
    The problem is, that setting value is placed in getValue method of the combo:

    Code:
     getValue: function() {
            // If the user has not changed the raw field value since a value was selected from the list,
            // then return the structured value from the selection. If the raw field value is different
            // than what would be displayed due to selection, return that raw value.
            var me = this,
                store = me.getStore(),
                picker = me.picker,
                rawValue = me.getRawValue(), //current value of text field
                value = me.value; //stored value from last selection or setValue() call
    
    
            // getValue may be called from initValue before a valid store is bound - may still be the default empty one.
            // Also, may be called before the store has been loaded.
            // In these cases, just return the value.
            // In other cases, check that the rawValue matches the selected records.
            if (!store.isEmptyStore && me.getDisplayValue() !== rawValue) {
                me.displayTplData = undefined;
                if (picker) {
                    // We do not need to hear about this clearing out of the value collection,
                    // so suspend events.
                    me.valueCollection.suspendEvents();
                    picker.getSelectionModel().deselectAll();
                    me.valueCollection.resumeEvents();
                    me.lastSelection = null;
                }
                // If the raw input value gets out of sync in a multiple ComboBox, then we have to give up.
                // Multiple is not designed for typing *and* displaying the comma separated result of selection.
                // Same in the case of forceSelection.
                // Unless the store is not yet loaded, which case will be handled in onLoad
                if (store.isLoaded() && (me.multiSelect || me.forceSelection)) {
                    value = me.value = undefined;
                } else {
                    value = me.value = rawValue;
                }
            }
    
    
            // Return null if value is undefined/null, not falsy.
            me.value = value == null ? null : value;
            return me.value;
        },
    And when you type into combo the setValue doesn't trigger, but when you bind a value and change the value in combo by typing, the binding triggers setValue and rawValue clears with it.
    The real case that annoying is: after fiddle is rendered, select all text in combo and try to type new value.

  4. #4
    Sencha Premium Member yorl1n's Avatar
    Join Date
    Mar 2015
    Location
    Germany
    Posts
    294

    Default

    evant, re-read you comment. Sorry, didn't get your solution from the first time. It is really workaround, while on initial load I have only id and provide to backend I should only id. I should every time find a record to bind and convert it before sending. Actually binding works properly, but the combo behaves improper in that case. At least from my point of view there should be no difference between using binded and normal value.I hope it will be fixed. Thanks.

  5. #5
    Sencha Premium Member yorl1n's Avatar
    Join Date
    Mar 2015
    Location
    Germany
    Posts
    294

    Default

    I have overridden the setValue of combo with:
    Code:
    setValue: function (value) {
                    var me = this;
                    if (value != null) {
                        return me.doSetValue(value);
                    } else {
                        if (!me.getStore().isEmptyStore && me.getDisplayValue() !== me.rawValue && me.getDisplayValue() != me.rawValue &&
                                me.getStore().isLoaded() && (me.multiSelect || me.forceSelection)) {
                            me.value = null;
                        } else {
                            me.suspendEvent('select');
                            me.valueCollection.beginUpdate();
                            me.pickerSelectionModel.deselectAll();
                            me.valueCollection.endUpdate();
                            me.lastSelectedRecords = null;
                            me.resumeEvent('select');
                        }
                    }
                }
    Could you please advise, what could be a side effects of this override?
    Thanks in advance.

  6. #6
    Sencha Premium Member yorl1n's Avatar
    Join Date
    Mar 2015
    Location
    Germany
    Posts
    294

    Default

    Eventually I used selection facepalm.png

  7. #7
    Sencha Premium Member yorl1n's Avatar
    Join Date
    Mar 2015
    Location
    Germany
    Posts
    294

    Default

    Something similar was here https://www.sencha.com/forum/showthread.php?291421 and was interpreted as a bug. Marked as fixed but seems not completely.

  8. #8
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    Binding doesn't provide any extra "magic" in terms of how components work. If you have no active selection then the value becomes null, that's how forceSelection works for combobox.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  9. #9
    Sencha Premium Member yorl1n's Avatar
    Join Date
    Mar 2015
    Location
    Germany
    Posts
    294

    Default

    Remove bind from the combo and use normal value and it will work proper, while rawValue will not replaced with null, so the magic happens. As I said the bind triggers setValue what isn't happening during normal value use. It is definitive a bug that you reject to accept. You have placed a setter logic into a getter function and now there is a problem.

  10. #10
    Sencha Premium Member yorl1n's Avatar
    Join Date
    Mar 2015
    Location
    Germany
    Posts
    294

    Default

    I have modified a fiddle to get a difference.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 25 Jul 2016, 2:00 AM
  2. Replies: 2
    Last Post: 14 Nov 2013, 6:54 PM
  3. combobox typeahead and forceselection problem
    By voytaz78 in forum Ext: Q&A
    Replies: 7
    Last Post: 30 Aug 2012, 6:23 AM
  4. ComboBox forceSelection Problem
    By dukz in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 18 Jul 2008, 11:12 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •