views:

124

answers:

1

Hi everybody,

I summarize the issue like this.

I use a form to edit user information which is loaded from the DB (I get these values through a JSONStore)

I want to enable/disable a combo depending on the loaded value of another combo.

Example: disable combo2 if the loaded value into combo1 = 0

  • if I load combo1 = 1, combo2 = 12 : Everything fine
  • if I load combo1 = 0, combo2 = 15 : Disable combo2

Any ideas? Thanks

+1  A: 

A listener like this should do the job:

formEditUser.getForm().on('actioncomplete',function(form,action) {
  if(combo1.getValue() == 0) {
    combo2.disable();
  } else if (combo1.getValue() == 1) {
    combo2.enable();
  }
})
Mchl
The change event might not fire without interactive change.
Lloyd
I see now what you mean, although it's not entirely clear what OP means by 'value is loaded into combo'. If he means value loaded into JsonStore then use JsonStore's `load` event to do this.
Mchl
The change event does not seem to work. The data is loaded into the form using the following command (formEditUser is a GridPanel, and it is into an ExtJS window): formEditUser.getForm().load({ url: 'gen/jsonUser.php', params:{IDUser:IDUser}, waitMsg: 'Loading...' });After this, I need to read the data loaded into combo1. In case the value is 0, then combo2 should be reset (clearValue()) and disabled.
Danilo
In this case fetch form's basicForm using `formEditUser.getForm()` and use it's `actioncomplete` listener. I'll update the code above in a moment.
Mchl
I was working on a similar code... but it does not seem to work. If I try something like this: formEditUser.getForm().on('actioncomplete',function(form,action) {var comboFaculties = Ext.getCmp('comboFacultiesPrereg'); alert(comboFaculties.getId());alert(comboFaculties.getValue());}and you know what happens? I can see the ID of the element but value gives an empty Alert. I tried delay:1000 but that does not help. I guess the problem is that when the event actioncomplete is fired, the combo has not yet its value.
Danilo
Strange.. In that case you might want to add `success` handler to your load command and see what happens: `formEditUser.getForm().load({ url: '', success: function(form,action) {}, ...)`
Mchl
BTW: In this function you can examine `action.result` to get the values straight from the server response, instead of fetching them from form fields.
Mchl
Probably I was writing something wrong in my tests and some of the above mentioned solutions may work anyway. Anyway now it works and I decided to implement it looking at action.result.data, that is skipping to load data into the form and go to read the value from there. Thanks a lot! :)
Danilo