PDA

View Full Version : Ext.form.DateField and calling JQuery function if valid



mjfigur
15 Jun 2011, 10:51 AM
All, I have the following code to create a DateField and it works well but now I am in need to checking to see if the date inputted is valid then execute a JQuery functions called: refreshEmp.

Here is the code:


new Ext.form.DateField({
id: dt.id,
applyTo: dt,
"format": 'm/d/Y',
invalidClass : 'ux-status-error',
validateOnBlur : true,

I read that there is the validate method but just new to ExtJs and cannot figure out how to put in an if statement that would then execute this JQuery function.

skirtle
16 Jun 2011, 4:54 PM
By a jQuery function I assume you just mean a JavaScript function? If you take a look at this page of the docs:

http://dev.sencha.com/deploy/ext-3.4.0/docs/?class=Ext.form.DateField

and scroll down to the very bottom, you'll see the last event is valid. There are a few ways to register event listeners, one of which is:


new Ext.form.DateField({
...
listeners: {
valid: function(dateField) {
refreshEmp(...);
}
}
});

Depending on what arguments refreshEmp() takes you may be able to reduce this down to just:


new Ext.form.DateField({
...
listeners: {valid: refreshEmp}
});

Alternatively, if you are explicitly calling validate() you might want to do something like this:


if (dateField.validate()) {
refreshEmp(...);
}

or even:


if (dateField.isValid()) {
refreshEmp(...);
}

mjfigur
17 Jun 2011, 7:38 AM
Thank you so much you have been such a major help in understanding the official documentation.