PDA

View Full Version : [FIXED][3.0RC1] Datefield:change event not firing



Mchl
22 Apr 2009, 12:27 PM
Don't know if this is a bug, or intended change.

Browser: FireFox 3
Code:


var win = new Ext.Window({
layout: 'form',
items: [
{
xtype: 'datefield',
fieldLabel: 'Date',
listeners: {
blur: function() {
console.log("blur");
},
change: function() {
console.log("change");
},

},
width: 100,
},
]
}).show();


Steps to reproduce:
1. Run the code
2. Put text insert in datefield
3. Use the date picker to select a date
4. Click outside of the window
- both blur and change are triggered
5. Make sure text input cursor is not in datefield
6. Use the date picker to select (different) date
7. Click outside of the window
- only blur is triggered

[edit]
Forgot to add: In Ext 2.2 'change' is triggered in both cases

Condor
22 Apr 2009, 10:02 PM
Are you using a locale file? Does it work without the locale file?

In that case it's a duplicate of this bug (http://extjs.com/forum/showthread.php?p=281130#post281130) (which is also present int Ext 2.2.1).

Mchl
22 Apr 2009, 10:56 PM
This happens with or without a locale file.

Here's HTML I use for tests


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="test.css">
<link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css">
<script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext/ext-all.js"></script>
<!--<script type="text/javascript" src="ext/source/locale/ext-lang-pl.js"></script>-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script type="text/javascript" src="test.js"></script>
</body>
</html>


Right now I am working around this issue by using 'select' event to trigger 'change' event.

Mchl
24 Apr 2009, 11:35 AM
Can anyone please confirm if it is a bug, or an expected behaviour in Ext3.0? I'd like to know if I'll need to modify my code.

Mchl
4 May 2009, 1:01 AM
Still exists in ExtJS 3.0 RC1.1

evant
4 May 2009, 1:42 AM
It's because of the delay in the focus() method.

Try something like this:



Ext.override(Ext.form.DateField, {
onSelect: function(m, d){
this.menu.hide();
(function(){
this.setValue(d);
this.fireEvent('select', this, d);
}).defer(10, this);
}
});

Animal
4 May 2009, 2:00 AM
The problem is the starting value is not registered when you start not focussed on the DateField, and then click the trigger.

The following override fixes it:



onTriggerClick : function(){
if(this.disabled){
return;
}
if(this.menu == null){
this.menu = new Ext.menu.DateMenu({
hideOnClick: false
});
}
this.onFocus();
Ext.apply(this.menu.picker, {
minDate : this.minValue,
maxDate : this.maxValue,
disabledDatesRE : this.disabledDatesRE,
disabledDatesText : this.disabledDatesText,
disabledDays : this.disabledDays,
disabledDaysText : this.disabledDaysText,
format : this.format,
showToday : this.showToday,
minText : String.format(this.minText, this.formatDate(this.minValue)),
maxText : String.format(this.maxText, this.formatDate(this.maxValue))
});
this.menu.picker.setValue(this.getValue() || new Date());
this.menu.show(this.el, "tl-bl?");
this.menuEvents('on');
}

Animal
4 May 2009, 2:04 AM
Another problem is that the Window's focus element steals focus from the DateField after you select the date.

This override is needed too to defer focusing until after the Window does its nefarious focus grabbing!



onMenuHide: function(){
this.menuEvents('un');
this.focus.defer(60, this);
}

mystix
4 May 2009, 2:34 AM
Another problem is that the Window's focus element steals focus from the DateField after you select the date.

This override is needed too to defer focusing until after the Window does its nefarious focus grabbing!



onMenuHide: function(){
this.menuEvents('un');
this.focus.defer(60, this);
}


Ext.Component.focus() has a built-in delay option -- just pass in true / a number value as the second argument


onMenuHide: function(){
this.menuEvents('un');
this.focus(false, 60);
}

Animal
4 May 2009, 2:46 AM
Yep, that works, and is better.

aconran
5 May 2009, 10:20 AM
Committed revision 3890.

Mchl
5 May 2009, 10:22 AM
Glad to hear that. Thanks everyone!