Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 35

Thread: [OPEN]ComboBox's setValue call with a remotely loaded Store

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #11
    Ext JS Premium Member
    Join Date
    May 2008
    Location
    Austria, Vienna
    Posts
    264

    Default

    I'm talking about the feature that starts with the code from Condor on page two of the thread.
    It loads just the single record by id to shows its name instead of its id.

  2. #12
    Ext JS Premium Member cdomigan's Avatar
    Join Date
    Mar 2007
    Posts
    148

    Default

    +1 for this bug please

  3. #13

    Default

    ya but even in extjs 4 , the problem is same the combo does not show the default value in the edit form because the store has not yet been loaded .

  4. #14
    Sencha User
    Join Date
    Jul 2011
    Posts
    1

    Default

    How about something like that (controlled by a parameter in the original ComboBox)?

    Code:
    Ext.define('myapp.SearchCombo', {
        extend: 'Ext.form.ComboBox',
        alias: 'widget.searchcombo',
    
        findRecord: function(field, value) {
            var ds = this.store,
                idx = ds.findExact(field, value);
    
            // lets get the record!
            if(idx === -1) {
                this.store.on('load', Ext.bind(this.setValue, this, [value]), null, {single: true});
                ds.load({
                    params: {
                        id: value
                    }
                });
                return;
            }
    
            return idx !== -1 ? ds.getAt(idx) : false;
        }
    });
    I use this Version to allow setValue without a loaded Store (e.g. when i have a foreign key to some huge dataset in a form record).

    For use in the default ComboBox we would of course need some config params and maybe also some further checks.

  5. #15
    Ext JS Premium Member
    Join Date
    Dec 2007
    Posts
    135

    Default

    +1

    Any news for extjs4?

  6. #16
    Sencha Premium Member
    Join Date
    Jan 2008
    Posts
    115

    Default Partial Solution

    Hi all,

    I found a little different solution. I pass an object in the record data and extract a record from it:

    Code:
    record: {id: 1, text: 'text', combobox: {id: 5, text: 'default_value'}}
    Then I added this to the setValueFunction:

    Code:
    Ext.override(Ext.form.ComboBox, {
        setValue: function(value, doSelect) {
        	    	
            var me = this,
                valueNotFoundText = me.valueNotFoundText,
                inputEl = me.inputEl,
                i, len, record,
                models = [],
                displayTplData = [],
                processedValue = [];
    
            if (me.store.loading) {
                // Called while the Store is loading. Ensure it is processed by the onLoad method.
                me.value = value;
                me.setHiddenValue(me.value);
                return me;
            }
    
            // This method processes multi-values, so ensure value is an array.
            value = Ext.Array.from(value);
            
            // Loop through values
            for (i = 0, len = value.length; i < len; i++) {
                record = value[i];
                if (!record || !record.isModel) {
                    record = me.findRecordByValue(record);
                }
                
                // is object, try to convert to model and push
                if (!record && typeof(value[i]) == 'object') {
                	
                	var model = me.store.getProxy().getModel().modelName;
                	record = Ext.create(model, value[i]);
                }
                
                // record found, select it.
                if (record) {
                	console.log(record);
                	
                    models.push(record);
                    displayTplData.push(record.data);
                    processedValue.push(record.get(me.valueField));
                }
                // record was not found, this could happen because
                // store is not loaded or they set a value not in the store
                else {
                    // If we are allowing insertion of values not represented in the Store, then set the value, and the display value
                    if (!me.forceSelection) {
                        displayTplData.push(value[i]);
                        processedValue.push(value[i]);
                    }
                    // Else, if valueNotFoundText is defined, display it, otherwise display nothing for this value
                    else if (Ext.isDefined(valueNotFoundText)) {
                        displayTplData.push(valueNotFoundText);
                    }
                }
            }
    
            // Set the value of this field. If we are multiselecting, then that is an array.
            me.setHiddenValue(processedValue);
            me.value = me.multiSelect ? processedValue : processedValue[0];
            if (!Ext.isDefined(me.value)) {
                me.value = null;
            }
            me.displayTplData = displayTplData; //store for getDisplayValue method
            me.lastSelection = me.valueModels = models;
    
            if (inputEl && me.emptyText && !Ext.isEmpty(value)) {
                inputEl.removeCls(me.emptyCls);
            }
    
            // Calculate raw value from the collection of Model data
            me.setRawValue(me.getDisplayValue());
            me.checkChange();
    
            if (doSelect !== false) {
                me.syncSelection();
            }
            me.applyEmptyText();
    
            return me;
        }
    });
    This avoids a couple of the mentioned problems, as the value is available immediatly to be submitted, and no extra request is made to the server to fetch the single record. Of course there are checks missing, but for now this works for me.
    Last edited by KajaSheen; 1 Mar 2012 at 6:28 AM. Reason: Small error found

  7. #17
    Ext JS Premium Member vishalg's Avatar
    Join Date
    Sep 2007
    Location
    Los Angeles, CA
    Posts
    75

    Exclamation I can't believe its still not fixed

    Wow this bug has been present since Ext 2. I have gotten around by pre-loading all my data stores at the start of the application but I would like to get away from that at some point.

    Please fix this in the framework.

    +1

  8. #18
    Sencha Premium Member
    Join Date
    Oct 2010
    Posts
    100

    Default

    This really should be fixed.

    Sencha devs! Any comments?

  9. #19
    Sencha User
    Join Date
    Jan 2012
    Posts
    6

    Default

    I've been wrestling with this one too. One slightly less hacktastic way I found was to have the proxy's "afterRequest" function set the combobox's value, because then you know the store has been loaded by that point. Keep in mind that it does not work if you have paging enabled in the proxy and your selected value is not in the first page of data. You might be able to add more logic in "afterRequest" to get around that though?

    I do agree that something like this should be base functionality, especially when using paging.

    Code:
    function CreateComboBoxWithStore(currValue, cbId)
    {
        var cb = Ext.create('Ext.form.ComboBox', {
            xtype: 'combo',
            id: cbId,
            store: Ext.create('Ext.data.Store', {
                autoLoad: true,
                fields: [
                    {
                        name: 'PRIMARYKEYCOLUMN'
                    },
                    {
                        name: 'DISPLAYCOLUMN'
                    }
                ],
                pageSize: 100,
                remoteFilter: true,
                proxy: {
                    type: 'ajax',
                    actionMethods: {
                        read: 'POST'
                    },
                    api: {
                        read: ---servlet call to get data---
                    },
                    reader: {
                        type: 'json',
                        root: 'data'
                    },
                    afterRequest: function (request, success)
                    {
                        cb.setValue(currValue);
                    }
                }
            }),
            queryMode: 'remote',
            displayField: 'DISPLAYCOLUMN',
            valueField: 'PRIMARYKEYCOLUMN'
        });
    
    
        return cb;
    }

  10. #20
    Ext JS Premium Member malstroem's Avatar
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    261

    Default

    Hi there,

    Id like to contribute my own little hackaround solution for this:
    Use the "valueNotFoundText" for what you want to display

    I was doing lot of effort with load-listeners (ComboStore load) and deferring the setValue until the store had been loaded... but every once in a while I faced problems again. Thats why I am not loading the comboStore at all anymore, but still can assign the right value to it... here is how:

    When loading e.g. a form with a combobox, I just load the id for the ComboBoxValue AND the matching display name for this record. Then I instaninate my combobox with:

    PHP Code:
    xtype'combobox',
    queryMode:'remote',
    forceSelectiontrue,
    store:Ext.create('Ext.data.Store', {
          
    model:'MyComboModel'
    }),
    name'category_id',
    valueField:'category_id',
    value: (this.record.category_id || ''),
    valueNotFoundText: (this.record.category_name || ''),
    hiddenValue'category_id',
    displayField'category_name' 
    That is how the combo shows the right valuetext without even having loaded the ComboStore... I know that this is a hack - but it works perfectly for me!

    Cheers Thomas

Page 2 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. Combobox: setValue happens before store is loaded?
    By hallikpapa in forum Ext 3.x: Help & Discussion
    Replies: 11
    Last Post: 10 Jul 2016, 3:00 AM
  2. Combobox loaded remotely and scriptTagProxy question..
    By ImperioG in forum Ext 3.x: Help & Discussion
    Replies: 7
    Last Post: 12 Oct 2010, 11:51 PM
  3. Replies: 2
    Last Post: 8 Nov 2007, 8:27 AM

Posting Permissions

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