PDA

View Full Version : Selectbox with null value



tomalex0
11 Nov 2010, 2:30 AM
Hi,

I have came across problem in select box, even if we set value as null the initial item in list will be selected and even if i select the first item it will not be reflected as value. It seems in version 0.99 and a change in selection only closes the list. Any how i have tried an override to get what i was looking. I have not checked it full.It may helpful for some one

For 0.99


Ext.override(Ext.form.Select, {
showComponent: function() {
if (Ext.is.Phone) {
this.getPicker().show();
}
else {
var listPanel = this.getListPanel();
listPanel.showBy(this.el, 'fade', false);
this.getList();
}
},
getList:function(){
var listPanel = this.getListPanel(),record = this.store.findRecord(this.valueField, this.value),index = (record) ? this.store.find(this.valueField, this.value) : '-1';
console.log("selectedindex----"+index);
console.log("thisvalue===="+this.value);
if(index == "-1"){
listPanel.down('#list').clearSelections();
} else{
listPanel.down('#list').getSelectionModel().select(index, false, true);
}
listPanel.doLayout();
},
setValue: function(v) {
var record = v ? this.store.findRecord(this.valueField, v): '',
hidden = this.hiddenField;

if (record && this.rendered) {
this.fieldEl.dom.value = this.prependText + ' ' + record.get(this.displayField);
this.value = record.get(this.valueField);
} else {
this.value = v;
}

if (hidden) {
hidden.value = this.value;
}
if(this.value == "" || this.value == "undefined"){
this.fieldEl.dom.value = "";
}
if(!Ext.is.phone){
this.getList();
}

return this;
}
});

tomalex0
11 Nov 2010, 5:07 AM
For 0.98.
Bug
List and value field is not reflected with changed value, when used setValue Method


Ext.override(Ext.form.Select, {
onMaskTap: function() {
if (this.disabled) {
return;
}

var me = this;

if (Ext.is.Phone) {
me.picker = new Ext.Picker({
slots: [{
align : 'center',
name : me.name,
valueField : me.valueField,
displayField: me.displayField,
value : me.getValue(),
store : me.store
}],
listeners: {
change: me.onPickerChange,
hide : me.onPickerHide,
scope : me
}
});

me.picker.show();
}
else {
me.list = me.createList();
me.list.showBy(me.el, 'fade', false);
me.getList();

}
},
getList:function(){
var me = this;
var listPanel = me.list,record = me.store.findRecord(me.valueField, me.value),index = (record) ? me.store.find(me.valueField, me.value) : '-1';
console.log(record);
console.log("selectedindex----"+index);
console.log("thisvalue===="+me.value);
console.log(me.list);
if(me.list){
if(index == "-1"){
me.list.clearSelections();
} else{
me.list.select(index, false, true);
}
me.list.doLayout();
}
},
setValue : function(v) {
var me = this,
record = v ? me.store.findRecord(me.valueField, v) : '',
hidden = me.hiddenField;

if (record && me.rendered) {
me.fieldEl.dom.value = me.prependText + ' ' + record.get(me.displayField);
me.value = record.get(me.valueField);
} else {
me.value = v;
}
if(this.value == "" || this.value == "undefined"){
me.fieldEl.dom.value = "";
}
if(!Ext.is.phone){
this.getList();
}
if (hidden) {
hidden.value = me.value;
}
return me;
}
});

tomalex0
11 Nov 2010, 10:53 AM
Modified Selectbox override for version 0.98


Ext.override(Ext.form.Select, {
onMaskTap: function() {
if (this.disabled) {
return;
}

var me = this;

if (Ext.is.Phone) {
me.picker = new Ext.Picker({
slots: [{
align : 'center',
name : me.name,
valueField : me.valueField,
displayField: me.displayField,
value : me.getValue(),
store : me.store
}],
listeners: {
change: me.onPickerChange,
hide : me.onPickerHide,
scope : me
}
});

me.picker.show();
}
else {
me.list = me.createList();
me.list.showBy(me.el, 'fade', false);
this.setListSelection(me.value);
}
},
setValue : function(v) {
// debugger;

var me = this,
record = v ? me.store.findRecord(me.valueField, v) : '',
hidden = me.hiddenField;

if (record && me.rendered) {
me.fieldEl.dom.value = me.prependText + ' ' + record.get(me.displayField);
me.value = record.get(me.valueField);
this.setListSelection(me.value);
} else {
var val =(record && v) ? v : '';
me.value = val;
if(me.fieldEl){
me.fieldEl.dom.value = val;
}
this.setListSelection(val);
}
if (hidden) {
hidden.value = me.value;
}
return me;
},
setListSelection:function(v){
if(!Ext.is.phone){
var me = this;
var record = me.store.findRecord(me.valueField, v);
var index = (record) ? me.store.find(me.valueField, v) : '-1';
if(me.list){
if(index == "-1"){
me.list.clearSelections();
} else{
me.list.select(index, false, true);
}
}
}
}
});

tomalex0
12 Nov 2010, 3:32 AM
Modied setValue function because setValue(0) makes no change in value even if the the store have value with 0;

Ext.override(Ext.form.Select, {
onMaskTap: function() {
if (this.disabled) {
return;
}

var me = this;

if (Ext.is.Phone) {
me.picker = new Ext.Picker({
slots: [{
align : 'center',
name : me.name,
valueField : me.valueField,
displayField: me.displayField,
value : me.getValue(),
store : me.store
}],
listeners: {
change: me.onPickerChange,
hide : me.onPickerHide,
scope : me
}
});

me.picker.show();
}
else {
me.list = me.createList();
me.list.showBy(me.el, 'fade', false);
this.setListSelection(me.value);
}
},
setValue : function(v) {
// debugger;
var displayval = "";
var me = this,
record = v ? me.store.findRecord(me.valueField, v) : '',
hidden = me.hiddenField;
if (record && me.rendered) {
me.fieldEl.dom.value = me.prependText + ' ' + record.get(me.displayField);
me.value = record.get(me.valueField);
this.setListSelection(me.value);
} else {
var setrecord = me.store.findRecord(me.valueField, v);
var val = v;
if (setrecord){
val = v ;
displayval = me.prependText + ' ' + setrecord.get(me.displayField);
}
me.value = val;
if(me.fieldEl){
me.fieldEl.dom.value = displayval;
}
this.setListSelection(val);
}
if (hidden) {
hidden.value = me.value;
}
return me;
},
setListSelection:function(v){
if(!Ext.is.phone){
var me = this;
var record = me.store.findRecord(me.valueField, v);
var index = (record) ? me.store.find(me.valueField, v) : '-1';
if(me.list){
if(index == "-1"){
me.list.clearSelections();
} else{
me.list.select(index, false, true);
}
}
}
}
});

tomalex0
29 Nov 2010, 4:37 AM
Override for Version 1



Ext.override(Ext.form.Select, {
showComponent: function() {
if (Ext.is.Phone) {
this.getPicker().show();
}
else {
var listPanel = this.getListPanel();
listPanel.showBy(this.el, 'fade', false);
this.setListSelection(this.value);
}

},
setValue : function(v) {
var record = v ? this.store.findRecord(this.valueField, v) : '',
hidden = this.hiddenField, displayval = "",setrecord, val = v;
if (record && this.rendered) {
this.fieldEl.dom.value = record.get(this.displayField);
this.value = record.get(this.valueField);
this.setListSelection(this.value);
} else {
setrecord = this.store.findRecord(this.valueField, v);
if (setrecord){
val = v ;
displayval = setrecord.get(this.displayField);
}
this.value = val;
if(this.fieldEl){
this.fieldEl.dom.value = displayval;
}
this.setListSelection(val);
}
if (hidden) {
hidden.value = this.value;
}
return this;
},
setListSelection:function(v){
if(!Ext.is.phone){
var record = this.store.findRecord(this.valueField, v),index = (record) ? this.store.find(this.valueField, v) : '-1',list = this.getListPanel().getComponent(0);
if(list){
if(index == "-1"){
list.getSelectionModel().deselectAll();
} else{
list.getSelectionModel().select(index, false, true);
}
}
}
}
});