tags:

views:

133

answers:

3

HI, I am just trying to set a field value and disable it at the same time. Can this be done in ext js? The docs are very weak on this subject.

something like this generates errors:

myForm.getForm().findField('start_date').setValue('').setDisabled(true);

I'm used to JQuery which does this sort of thing nicely but haven't had luck with Ext.

Thanks for any help.

A: 

This is because setValue() method doesn't return field object. You cannot use setDisabled() in such way.

EDIT: (For those down-voting morons)

From ExtJS documentation:

method: setValue(value)

Parameters:
value : Mixed
The value to set

Returns:
void
Thevs
thanks guys, i'll figure out another way.
29er
+1  A: 

Actually, Field.setValue does in fact return a reference to the field (docs), so you should be able to call setDisabled (inherited from Component) as you have it. You must have some other issue going on. Maybe findField('start_date') is returning null. You have to make sure all the return values are what you expect. Use Firebug to figure out the error, or break apart your statement and see which call is actually failing.

Anything is "chainable" as long as the return value is the object itself (usually denoted as this in the docs). In jQuery, everything operates on DOM elements, so it is consistent. In Ext, you have lots of components with various behaviors. Sometimes chaining makes sense, sometimes it does not -- just make sure you check the docs when you aren't sure.

bmoeskau
A: 

i agree with bmoeskau it should work if the field is there and found by the form. I would advise you to to it something like that to prevent errors:

var field = myForm.getForm().findField('xyz');
if(field !== undefined)
{
    field.setValue('');
    field.setDisabled(true);
}
else
{
    // Error Handling
}
Nexum