Hybrid View

  1. #1
    Touch Premium Member
    Join Date
    Mar 2011
    Posts
    25
    Vote Rating
    1
    gubespam is on a distinguished road

      0  

    Question Reset or clear value of a combo box

    Reset or clear value of a combo box


    Using Ext 4.0 pr 3.

    I have a combo box whose value I would like to clear as a result of a user action. I can successfully "clear" the combo box so that it visually appears to be cleared, but after doing so, the combobox will no longer allow the user to select the same value again (eg. user selects "Rover", clicks "Clear", then tries to select "Rover" again). The combobox just ignores these clicks until the user selects a different value than before. The example below shows that Ext doesn't even fire the "select" event when the user the same value after the clear.

    I have tried many different approaches (see below) but none of them seem to work. Is this a bug or am I doing something wrong?

    Code:
    Ext.regModel('Dog', {
        fields: [
            'name'
        ]
    });
    
    var petStore = new Ext.data.Store({
        model: 'Dog',
        data: [
           {id:123,name:'Rover'},
           {id:456,name:'Alfred'}
        ]
    });
    
    // ComboBox with list of clients
    var petCombo = new Ext.form.ComboBox({
        id: 'pet-combo',
        name : 'dog',
        valueField: 'name',
        displayField: 'name',
        allowBlank: false, // doesn't seem to do anything
        emptyText : "Pick a pet",
        fieldLabel: "Dog",
        store: petStore,
        queryMode: 'local',
        forceSelection: true,
        listeners:{
            scope: this,
            'select': function(cmb, recs, idx) {
                console.log('selected:' + (recs.length > 0 ? recs[0].get('name') : undefined));
            }
        },
    });
    
    var petForm = Ext.create('Ext.form.FormPanel', {
        frame : true,
        title : "Pet Store",
        width : 150,
        fieldDefaults : {
            labelWidth : 50
        },
        items: [
            petCombo,
        {
            xtype: 'button',
            text : "Clear",
            handler : function() {
                petForm.getForm().reset();
                var cc = Ext.getCmp('pet-combo');
                cc.clearValue();
                cc.reset();
                cc.setValue("");
                cc.setValue(null);
                cc.setValue(undefined);
            }
        } ]
    });

  2. #2
    Touch Premium Member
    Join Date
    Mar 2011
    Posts
    25
    Vote Rating
    1
    gubespam is on a distinguished road

      0  

    Default


    After digging around in the Ext 4 source code and trying various options, I found a workaround.

    It appears that the root of the problem is in ComboBox.setValue(). This method ignores empty values (like undefined), but not empty arrays. As a result, reset() effectively does nothing when no original value is specified for the combo box, because originalValue=undefined and reset() calls setValue(originalValue). On the other hand, clearValue() calls setValue() with an empty array.

    Ultimately, the reason users cannot re-select the value that was selected before (even after calling clearValue()), is that the selection model still thinks something is selected. It thinks this because setValue() does not update the selection model when passed 'undefined' or an empty array.

    The following workaround seems to work as desired (clear value, reset "unselected text" and allow user to select previous value again):

    Code:
    cc.clearValue();
    cc.applyEmptyText();
    cc.getPicker().getSelectionModel().doMultiSelect([], false);

  3. #3
    Touch Premium Member
    Join Date
    Mar 2011
    Posts
    25
    Vote Rating
    1
    gubespam is on a distinguished road

      0  

    Exclamation


    Moderator: Please move this to the bug fourm for Ext 4.x. I did not know whether this was a bug when I originally created the thread.

  4. #4
    Sencha - Architect Dev Team jjohnston's Avatar
    Join Date
    Sep 2010
    Posts
    516
    Vote Rating
    17
    jjohnston will become famous soon enough jjohnston will become famous soon enough

      0  

    Default


    I've replied to this in the bug forum's post: http://www.sencha.com/forum/showthre...of-a-combo-box

    I'm unable to reproduce this issue in beta1, it seems to have been fixed. Can you please verify?

Similar Threads

  1. BasicForm.reset() does not clear fields?
    By dante in forum Ext 2.x: Help & Discussion
    Replies: 6
    Last Post: 30 May 2008, 4:14 AM
  2. reset form or clear all fields
    By hobbes in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 24 Apr 2008, 4:49 AM
  3. Reset button to clear form values?
    By onmission in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 17 Nov 2007, 11:34 AM
  4. Hwo to clear/empty/reset ComboBox/Store?
    By franzisk in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 21 Jun 2007, 10:19 AM
  5. ComboBox and clear / reset issues
    By mikegiddens in forum Ext 1.x: Help & Discussion
    Replies: 6
    Last Post: 18 Jun 2007, 2:34 PM

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi