PDA

View Full Version : Override TextField blur event



felsangom
12 Aug 2009, 2:21 PM
Hello!

I'm sorry about this newbie question, but how can I override the TextField blur event?
I'm trying with the code below, but the overrided blur event never gets called:


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

<script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext-3.0.0/ext-all.js"></script>
<script type="text/javascript">
Ext.onReady(function() {

//Create a anonymous function to override TextField
(function() {
//Store the original blur event
var originalBlur = Ext.form.TextField.prototype.blur;

//Override TextField
Ext.override(Ext.form.TextField, {
upper: false,

blur: function(field) {
//If the upper property is true
if (this.upper) {
//Change the text of the TextField to uppercase
field.setValue(field.getValue().toUpperCase());
}

//call default TextField blur
originalBlur.apply(this, arguments);
}
});
})();

//Create a textfield
var textField = new Ext.form.TextField({
fieldLabel: 'Nome',
width: 150,
upper: true
});

//Create the form
var form = new Ext.form.FormPanel({
layout: 'form',
items: textField
});

//Create the window
var window = new Ext.Window({
title: 'Override test',
width: 300,
height: 300,
layout: 'fit',
items: form
});
window.show();
});
</script>
</head>
<body>
</body>
</html>I appreciate any help.
Thanks

felsangom
12 Aug 2009, 2:28 PM
Well, maybe if I use the right event, it works... :D



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

<script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext-3.0.0/ext-all.js"></script>
<script type="text/javascript">
Ext.onReady(function() {
//Create a anonymous function to override TextField
(function() {
//Store the original blur event
var originalBlur = Ext.form.TextField.prototype.onBlur;

//Override TextField
Ext.override(Ext.form.TextField, {
upper: false,
onBlur: function() {
//If the upper property is true
if (this.upper) {
//Change the text of the TextField to uppercase
this.setValue(this.getValue().toUpperCase());
}

//call default TextField blur
originalBlur.apply(this, arguments);
}
});
})();

//Create a textfield
var textField = new Ext.form.TextField({
fieldLabel: 'Nome',
width: 150,
upper: true
});

//Create the form
var form = new Ext.form.FormPanel({
layout: 'form',
items: textField
});

//Create the window
var window = new Ext.Window({
title: 'Override test',
width: 300,
height: 300,
layout: 'fit',
items: form
});
window.show();
});
</script>
</head>
<body>
</body>
</html>

felsangom
12 Aug 2009, 2:29 PM
Thanks anyway!