View Full Version : Change form element types on the fly?

31 Jan 2008, 10:07 AM
In an attempt to reuse a form I have a need where in some cases I might want to change a plain TextField to a ComboBox as the entry/selection tool for the same data value.

If I initially configure the field as as a TextField, how might I go about replacing that field with a ComboBox at runtime if special conditions warrant doing so.

I realize I could probably just present an empty enterable combo in lieu of a TextField, but in the majority of cases a normal TextField will be more appropriate.

I'm assuming this is possible (this is ExtJS). Just looking for hints about how to approach the problem.

31 Jan 2008, 3:11 PM
There's nothing built in to do that. You could theoretically render both fields, make one hidden, then show it when needed, possibly changing it's position so that it appears in the same place. You could also write some sort of 'replace' function that removes the old field, adds a new one and calls doLayout.

1 Feb 2008, 7:52 AM

Thanks for the hints and the confirmation that a built-in solution doesn't exist. I've already played with your first suggestion (toggling the visibility of two fields) and getting the result I want wasn't as straightforward or simple as I'd hoped. There is some extra work involved to also show/hide labels.

I'll look into your replace suggestion.

2 Feb 2008, 4:43 AM
Another solution would be to use a combobox all the time, but hide the trigger if it isn't used.