Results 1 to 1 of 1

Thread: ComboBox.setValue (remote/local)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Aug 2009
    Vote Rating

    Lightbulb ComboBox.setValue (remote/local)

    Here's a piece of code that allows you not to ever think about the combobox's store state when dealing with setValue() with a local or remote combobox. Calling setValue multiple times on a remote combobox will work as well, it will automatically load the value from the server first (by sending the value as the [valueField] param to the server) and then select it. Calling setValue() on a remote combobox will also make sure that any active requests are cancelled before proceeding. In addition, the callbacks won't execute if the combobox has been destroyed.

    Ext.override(Ext.form.ComboBox, {
        setValue: Ext.form.ComboBox.prototype.setValue.createInterceptor(function(v, loadRecord) {
            loadRecord = !(loadRecord === false);
            if (!this.isDestroyed && loadRecord) {
                var cbo = this,
                    store =,
                    isLocalMode = cbo.mode === 'local',
                    vField = cbo.valueField,
                    callback = function(rec, options, success) {
                        if (success && {
                            cbo.setValue(v, false);
                if (isLocalMode && !Ext.isDefined(store.totalLength)) {
                        'load': callback,
                        scope: cbo,
                        single: true
                    if (!store.autoLoad) {
                    return false;
                else if (!isLocalMode) {
                    var rec = cbo.findRecord(vField, v);
                    if (!rec) {
                        var readRequest =,
                            params = {};
                        if (readRequest) {
                        params[vField] = v;
                            callback: callback,
                            params: params
                        return false;
    Last edited by plalx; 27 May 2011 at 11:04 AM. Reason: Refactored with createInterceptor

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