﻿Ext.override(Ext.form.ComboBox, {
  setValue: function(v) {
    if (this.mode == 'remote' && this.store.totalLength === undefined) {
      this.store.on('load', this.setValue.createDelegate(this, arguments), null, { single: true });
      if (this.store.lastOptions === null) {
        this.store.load();
      }
      return;
    }
    var text = v;
    if (this.valueField) {
      var r = this.findRecord(this.valueField, v);
      if (r) {
        text = r.data[this.displayField];
      } else if (this.valueNotFoundText !== undefined) {
        text = this.valueNotFoundText;
      }
    }
    this.lastSelectionText = text;
    if (this.hiddenField) {
      this.hiddenField.value = v;
    }
    Ext.form.ComboBox.superclass.setValue.call(this, text);
    this.value = v;
  }
});
