PDA

View Full Version : [OPEN-1416] ComboBox's reset() bug



Daniil
12 Nov 2010, 1:13 AM
Ext version tested:


Ext 3.3.0



Browser versions tested against:


IE8
FF3



Operating System:


Win7



Description:


Hi Sencha team,
In my application I faced the problem when use comboBox.reset(). It sets a value instead of clearing.
I investigated this problem and discovered the minor bug in the ComboBox's findRecord() function.
Internally the reset() calls findRecord("someProp", ""). There is a condition:

if (r.data[prop] == value) {
record = r;
return false;
}The bug happens when r.data[prop] is zero, because 0 == "" is true.



Possible fix:



Ext.form.ComboBox.override({
findRecord : function(prop, value) {
var record;
if (this.store.getCount() > 0) {
this.store.each(function(r) {
if (r.data[prop] === value) { //instead of (r.data[prop] == value)
record = r;
return false;
}
});
}
return record;
}
});

Daniil
16 Nov 2010, 8:45 AM
Bump...

Any update?

Daniil
24 Nov 2010, 7:00 AM
Any feedback would be really appreciated:)

Condor
25 Nov 2010, 7:53 AM
combobox.findRecord is used to check if the user input (always a String!) is in the store, so checking with '==' is fine!

You could use combobox.store.findExact instead (this one does do a '===' compare).

Daniil
25 Nov 2010, 8:41 AM
Thank you for the reply.

Maybe you're right findRecord() is fine (it was just my fix). But it means that reset() is not fine.

I do not use findRecord(), I use reset().

Here is a test case. Just press a button.

Code to reproduce

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

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

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

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

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

Ext.onReady(function() {
new Ext.form.ComboBox({
id: "ComboBox1",
renderTo: Ext.getBody(),
displayField: "state",
triggerAction: "all",
valueField: "abbr",
store: new Ext.data.Store({
autoLoad: true,
reader: new Ext.data.ArrayReader({
fields: [{ name: "abbr" }, { name: "state" }, { name: "nick"}]
}),
proxy: new Ext.data.MemoryProxy(
[
[60, "Alabama", "The Heart of Dixie"],
[1, "Alaska", "The Land of the Midnight Sun"],
[0, "Arizona", "The Grand Canyon State"],
[3, "Arkansas", "The Natural State"]
],
false)
})
});
new Ext.Button({
renderTo: Ext.getBody(),
text: "Reset",
handler: function(item, e) {
Ext.getCmp("ComboBox1").reset();
}
});
});
</script>

</head>
<body>
</body>
</html>

xaka
6 Dec 2010, 5:58 AM
Any updates? I've got this bug too. I was expecting that reset() will do right work and fixed it only by changing findRecord call. I'm disagree that checking with '==' is fine, because it does unexpected result. At least it must be documented somewhere.

Thank you for great product!