问题
In the project I'm working on, I have forms I sometimes have to fill by code.
Let's say I have two comboboxes : combo1 and combo2. They are both required by default (allowBlank : false). On combo1's select event, I set combo2's allowBlank property to true and clear it. Everything's good so far, while user is filling the form.
When I use combo1's setValue method, it doesn't trigger the select event, so combo2 is still required when I don't want it to be. What is a good way to solve this problem? Should I fire the events manually after setting values?
回答1:
Yes, you need to trigger the events manually.
No UI events are triggered with JavaScript. This is to prevent endless loops and other undesired side-effects while interacting with the page programmatically.
In ExtJS, there is component.fireEvent(...) for that purpose.
来源:https://stackoverflow.com/questions/4591625/what-is-a-good-way-of-filling-a-form-in-extjs-by-code-and-fire-the-events-for-e