PDA

View Full Version : textfield value on blur



Stephan123
9 Oct 2011, 4:59 AM
Hello !

I have a simple form.
In this form is a textfield for a zip.
When the 'blur event' on this field an ajax request
send the field value to the server.


xtype: 'textfield',
fieldLabel: 'PLZ *',
width: 50,
maxLength: 5,
minLength: 5,
allowBlank: false,
id: 'zip',
maskRe: /^[0-9]$/,
listeners: {
blur: function(field){

if(!this.isValid()){
showMsgBox('Bitte PLZ überprüfen !');
return;
}

Ext.Ajax.request({
url : '/admin/company/findregion/',
method : 'POST',
params : {
plz : field.value
},
success : function(response, action) {

},
failure : function(response, options) {

}
});

}
}

When i change the value of the textfield the old value is sending to the server.
What is wrong ?

Your sincerly

Stephan

kavolorn
9 Oct 2011, 7:19 AM
Hi

Try to use getValue() method. This works for me:


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>TextField value on blur</title>
<link rel="stylesheet" type="text/css" href="http://dev.sencha.com/deploy/ext-3.4.0/resources/css/ext-all.css" />
<script type="text/javascript" src="http://dev.sencha.com/deploy/ext-3.4.0/adapter/ext/ext-base-debug.js"></script>
<script type="text/javascript" src="http://dev.sencha.com/deploy/ext-3.4.0/ext-all-debug.js"></script>
<script type="application/javascript">
Ext.onReady(function() {
new Ext.Viewport({
layout : 'border',
renderTo : Ext.getBody(),
items : [{
region : 'center',
layout : 'form',
items : [{
xtype : 'textfield',
fieldLabel : 'PLZ *',
width : 50,
maxLength : 5,
minLength : 5,
allowBlank : false,
id : 'zip',
maskRe : /^[0-9]$/,
listeners : {
blur : function(field) {
if (!field.isValid()) {
alert('Bitte PLZ überprüfen !');
return;
}
Ext.Ajax.request({
url : '/admin/company/findregion/',
method : 'POST',
params : {
plz : field.getValue()
},
success : function(response, action) {

},
failure : function(response, options) {

}
});
}
}
}]
}]
});
});
</script>
</head>
<body></body>
</html>