View Full Version : wait for ajax-request (using TextFieldRemoteVal in Ext.form)

8 Jan 2010, 1:09 AM
Do you know the Ext.form-extension TextFieldRemoteVal? If not pleace look here first: http://www.extjs.com/forum/showthread.php?t=4807

I have a formular to edit a user.
The field "username" is an instance of the class "Ext.form.TextFieldRemoteVal"

To create the submit-button I've used the following code:

text: "submit",
handler: function() {
if(user_edit_form.getForm().isValid()) {

If I click on this button he doesn't wait for the result of the "username"-validation because it's made by AJAX ...
And even if this request returns an false returnValue - you can submit this form ...

Now I'm searching for a solution in one of the following ways:

check if ALL ajax-confirmation has been submitted
check if this specific ajax-confirmation has been submitted (here I have to know how often I want to use this field - not good for dynamic forms)
I change the isValid() function of the class "TextFieldRemoteVal" - but I don't know how :-/
the fastest and (in my eyes) a quick-and-dirty-solution change the submit-handler so you check the username and if this succeeds - you submit the form ... (this can't work with dynamic forms or a form with "standardSubmit: true" !!!)

If anyone has an suitable solution (excepted my solution-way 4) - please write as fast as possible ;)

Here's my full code example:

var user_edit_form = new Ext.FormPanel({
labelWidth: 160, // label settings here cascade unless overridden
labelAlign: 'left',
id: 'user-edit-form',
frame: true,
title: 'Edit your user',
bodyStyle: 'padding:5px 25px 0 5px',
defaults: {
anchor: '100%',
selectOnFocus: true,
msgTarget: 'side'
defaultType: 'textfield',

// use the standardSubmit
standardSubmit: true,

items: [
fieldLabel: 'loginname',
invalidText: 'This loginname still exists in the system',
name: 'useredit[loginname]',
value: data.loginname,
allowBlank: false,
id: 'loginname',

remoteValidation: 'onBlur',
urlRemoteVal: '?ajax=check_loginname',
method: 'POST',
timeout: 20
}, {
fieldLabel: 'change your password',
name: 'useredit[password]',
value: data.password,
id: 'password',
maxLength: 255
}, {
fieldLabel: 'firstname',
name: 'useredit[firstname]',
value: data.firstname,
allowBlank: false,
maxLength: 255
}, {
fieldLabel: 'lastname',
name: 'useredit[lastname]',
value: data.lastname,
allowBlank: false,
maxLength: 255

buttons: [{
text: "submit",
handler: function() {
if(user_edit_form.getForm().isValid()) {