PDA

View Full Version : ComboBox .isDirty() issue



Daniil
15 Jan 2011, 4:20 AM
Hi ExtJS team,

Ext version tested:


Ext 3.3.0



Description:


Is there any restriction to set value of ComboBox to null?
I face to some issue with ComboBox's .isDirty() method when initial value is null.



Test Case:



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title id='title'>ComboBox .isDirty() issue</title>

<link rel="stylesheet" type="text/css" href="../../extjs/resources/css/ext-all.css" />

<script type="text/javascript" src="../../extjs/adapter/ext/ext-base.js"></script>

<script type="text/javascript" src="../../extjs/ext-all-debug.js"></script>

<script type="text/javascript">
Ext.BLANK_IMAGE_URL = '../../extjs/resources/images/default/s.gif';

Ext.onReady(function () {
new Ext.form.ComboBox({
id : "ComboBox1",
renderTo : Ext.getBody(),
value : null,
mode : "local",
store : ["Item1", "Item2"]
});
new Ext.Button({
renderTo : Ext.getBody(),
text : "combo.isDirty()",
handler : function (item, e) {
alert(Ext.getCmp("ComboBox1").isDirty());
}
});
});
</script>

</head>
<body>
</body>
</html>
Steps to reproduce the problem:


Click on button, you will see "false"
Click on trigger
Do NOT choose any item
Just "blur" combo
Click on button, you will see "true" but "false" is expected
because actually there was no change of value.

Daniil
19 Jan 2011, 1:21 AM
Bump... Any update?:)

Condor
19 Jan 2011, 1:28 AM
The ComboBox value is stored in an <input>, so it can only reliably hold string values.

Daniil
19 Jan 2011, 1:47 AM
Thank you for the answer.

So, in case when I use FormPanel.load() and returned by server record has 'null' value for ComboBox have I to manually check on 'null', right?

Condor
19 Jan 2011, 1:55 AM
You could do an inline override:

{
xtype: 'combo',
...
setValue: function(v) {
this.constructor.prototype.setValue.call(this, v || '');
}
}

Condor
19 Jan 2011, 1:56 AM
I would like to note that IMHO Ext.form.Field should be modified to handle 'null' the same as it does 'undefined' now.

Daniil
19 Jan 2011, 2:05 AM
Thanks for the suggestion.

And I agreed with you, it would be good if it will handle a 'null' case also.

I see the following code of Ext.form.Field .setValue():

setValue : function(v){
this.value = v;
if(this.rendered){
this.el.dom.value = (Ext.isEmpty(v) ? '' : v);
this.validate();
}
return this;
}

What way would you change this?

Condor
19 Jan 2011, 2:18 AM
Not sure yet, but maybe:

Ext.override(Ext.form.Field, {
setValue : function(v){
v = Ext.isEmpty(v) ? '' : v;
this.value = v;
if(this.rendered){
this.el.dom.value = v;
this.validate();
}
return this;
}
});

Daniil
24 Jan 2011, 9:38 AM
Looks good. Any chance to get it in pure ExtJS?