ComboBox doesn't post user-entered data - with workaround

  • //snip
    items: [
    new Ext.form.ComboBox({
    fieldLabel: 'Acquisition Type',
    value: 'myVal',
    id:'myComboList',
    hiddenName: 'myCombo',
    anchor:'95%',
    typeAhead: false,
    displayField:'name',
    editable:true,
    triggerAction: 'all',
    lazyInit:false,
    emptyText:'Select...',
    store: getComboBoxDS()
    })
    ]

    Consider the case where the combobox consists of three values:
    Apple
    Orange
    Pineapple

    If a user selects any of those values, I'm able to read them via. on the server side when responding to a post: ie.

    //Java sample...but issue is language-agnostic
    String fruit = req.getParameter("myCombo");

    will set fruit appropriately to "Apple", "Orange", or "Pineapple"

    However, say instead of select an item from the dropdown, a user opts to enter, "Tomato". On the server-side, fruit won't get set to "Tomato".


    Work-around:
    I updated Ext-all.js to add an onBlur handler to ComboBox, and things are working for me now. FWIW, my onBlur handler just looks like the following:

    onBlur : function(){
    this.setValue(this.getValue());
    },

    this forces the combobox to set the value of it's backing hidden field, and everything posts as expected.


    One question:

    Rather than update ext-all.js directly, it seems like it would be better to just extend ComboBox and add my handler to the sub-class. Can somebody point me in the right direction to get started with sub-classing Ext components?

    Cheers.


  • There is a tutorial on extending Ext classes http://extjs.com/learn. There are also numerous examples of extending/overriding functionality in the forums.

    You should not be modifying ext-all directly, rather add your overrides after it. Instead of adding on onBlur function, you could also just handle that in a listener for the blur event.


  • I was under the assumption that the forceSelection:false (which is default) would have allowed for tomato to have been accepted as a new entry. Did I interpret it wrong?

    forceSelection
    forceSelection : Boolean
    True to restrict the selected value to one of the values in the list, false to allow the user to set arbitrary text into the field (defaults to false)
    This config option is defined by ComboBox.


  • Heh, I ran into this exact same issue today, and was also under the impression that forceSelection should be allowing whatever value as described.







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about ComboBox doesn't post user-entered data - with workaround , Please add it free.