Results 1 to 4 of 4

Thread: Change form element types on the fly?

  1. #1
    Ext JS Premium Member
    Join Date
    Nov 2007
    Posts
    78

    Default Change form element types on the fly?

    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.

  2. #2
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854

    Default

    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.

  3. #3
    Ext JS Premium Member
    Join Date
    Nov 2007
    Posts
    78

    Default

    Tim,

    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.

  4. #4
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default

    Another solution would be to use a combobox all the time, but hide the trigger if it isn't used.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •