0

I'm building a "fix" for combobox because it shows the value field instead of the display field in the textbox when you open the row editor. However, to do this I have to change the value of the combobox just before is sent to the server. To do this, my idea was to hook to beforeedit event of row editing plugin.

The biggest problem, is that I can't find a way to reach the grid which I'm row editing, or directly the row editing plugin.

Only thing I can find is the form where the combobox is in with combobox.up('form') and I can hook to those events, but I think they don't happen "early enough". I can't find a way to obtain the rowediting plugin from the form however :\

Any idea on how to solve this problem?

Edit 1:

As sha requested, this is the problem shown as images:

http://dl.dropbox.com/u/762638/Files/Images/Screenshots/show_combobox_extjs_problem/part_1.png

http://dl.dropbox.com/u/762638/Files/Images/Screenshots/show_combobox_extjs_problem/part_2.png

http://dl.dropbox.com/u/762638/Files/Images/Screenshots/show_combobox_extjs_problem/part_3.png

And here you can find the combobox code:

Ext.define('Fdd.form.field.XComboBox', {
  extend: 'Ext.form.field.ComboBox',
  alias: 'widget.xcombobox',

  displayField: 'display',
  queryMode: 'local',
  valueField: 'value',
  //forceSelection: true,

  /**
   *
   * @property {Ext.form.Panel} parentForm
   * Contains a reference to the combobox form, used internally
   *
   * @readonly
   */
  parentForm: null,
  /**
   *
   * @property {Boolean} hasChanged
   * `true` if the combobox has changed its value since last show/hide cycle
   */
  hasChanged: false,

  statics: {
    xcomboboxRenderer: function(xcombobox) {
      return function(value, metaData, record, rowIndex) {
        if (value === null)
          return '';
        return xcombobox.store.getById(value.toString()).get('display');
      }
    }
  },

  initComponent: function() {
    var me                  = this;
    var xComboBoxStoreClass = 'Fdd.data.XComboBoxStore';
    var xComboBoxStoreKey   = Ext.getClassName(me);

    // FIXME: Fix default value to be display and not value field
    // Create the combo store if not exists
    me.createComboStoreIfNotExists = function() {
      // If store is not set, we can't do anything
      if (!me.store)
        return false;

      // If the store is an array, we break the functionality and return to a normal combobox
      // because XComboBox is to avoid problems with stores
      if (Ext.isArray(me.store))
        return false;

      // We need the object for the parent store, to avoid missing references
      var parentStore = null;
      if (Ext.isString(me.store))
        parentStore = Ext.getStore(me.store)
      else
        parentStore = me.store;

      // If the store doesn't have the updatedAt variable, we don't enable functionalities
      // because that is a requirement
      if (!Ext.isDefined(parentStore.updatedAt))
        return false;

      // If parent store is of type XComboBoxStore, it means that we already have created a combo store
      if (Ext.getClassName(parentStore) == xComboBoxStoreClass)
        return false;

      var comboStore = Fdd.NamespaceKeyedStoreManager.lookup(xComboBoxStoreKey, parentStore.storeId);
      if (!comboStore) {
        comboStore = Ext.create(xComboBoxStoreClass, parentStore);
        Fdd.NamespaceKeyedStoreManager.register(xComboBoxStoreKey, parentStore.storeId, comboStore);
      }
      me.store = comboStore;

      //me.on('afterrender', function(obj, eOpts) {
      //  obj.setValue(1);
      //});

      return comboStore;
    }

    // Load data if required
    me.loadUpdatedData = function() {
      me.createComboStoreIfNotExists();
      if (me.store)
        Fdd.NamespaceKeyedStoreManager.lookup(xComboBoxStoreKey, me.store.parentStore.storeId).loadIfNotUpdated();
    };

    // Load data if required
    me.loadUpdatedData();

    // Fires loadUpdatedData every time trigger is pressed
    me.on('expand', function(obj) {
      obj.loadUpdatedData();
    });

    // TODO: Building a fix for the problem combobox input field shows the value field instead of the display field
    me.on('boxready', function(obj) {
      obj.parentForm = obj.up('form');
      console.log(obj.parentForm);
      obj.mon(obj.parentForm, 'edit', function(editor) {
        console.log("beforeaction");
        console.log(e.originalValue);
        console.log(obj);
        if (!obj.hasChanged)
          obj.setValue(obj.originalValue);
      });
      obj.mon(obj.parentForm, 'show', function() {
        /*console.log("move:");
        console.log(obj.getValue());
        console.log(obj.inputEl.dom.value);*/
        obj.hasChanged = false;

        if (obj.parentForm) {
          if (obj.getValue() === null)
            obj.inputEl.dom.value = "";
          else
            obj.inputEl.dom.value = obj.store.getById(obj.getValue().toString()).get('display');
        }
      });
    });
    me.on('change', function(obj) {
      obj.hasChanged = true;
    });

    // Call parent initializator
    me.callParent(arguments);
  }
});

The code we are talking about starts from the TODO.

I suggest to ignore previous part because is used to create a store-duplicate to avoid filtering and buffered stores.

Edit 2:

It seems like the problem I'm trying to solve through this question is not directly related to the issue I'm trying to solve anymore (solved in a different way) so the question can be closed.

Thanks anyway.

8
  • Fix for combobox? Really? Why don't you use another combobox in the editor?
    – sha
    Jun 1, 2012 at 16:09
  • I don't understand your comment, why should I use another combobox? The problem is how the combobox behaves, not having multiple combobox. Jun 1, 2012 at 16:11
  • There is no problem with how combobox behaves. In our projects we have this construction everywhere. When you use roweditor - do you edit this field in textfield or in combobox too?
    – sha
    Jun 1, 2012 at 16:13
  • For me, the text field of the combobox should show the display field, not the value field. Normally the combobox show the display field in there, only when you reload it with a value already set it shows the value field, so it's not correct. By the way this is offtopic, to fix this I only need a reference to the row editing plugin. Jun 1, 2012 at 16:27
  • I think you're trying to solve wrong problem. Can you please post code for your grid?
    – sha
    Jun 1, 2012 at 16:31

1 Answer 1

1

There is no bug in the standard Combobox control for this. I use it in many places in my projects without any issues.

Make sure you have matching types for valueFields in editor combobox, grid combobox and store itself.

1
  • Thanks a lot, even for following me in that long discussion. Jun 1, 2012 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.