jQuery UI Widgets Forums General Discussions Questions about jqxForm + jqxWindow lifecycle, reinitialization, and dynamic fie

This topic contains 2 replies, has 2 voices, and was last updated by  Tattoo 1 month ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author

  • Tattoo
    Participant

    Hi everyone,

    I’m working on a modal editor that uses jqxWindow with a jqxForm inside it. The form is mostly static, but one of the fields needs to switch between different widget types depending on user input (for example, swapping a text input for a number input or a dropdown).

    I’m running into some lifecycle questions and would appreciate clarification on the recommended approach.

    1. jqxForm reinitialization
    If I call jqxForm() more than once on the same element, the form appears to rebuild its internal DOM. When that happens, any widgets I created inside the form (like a number input or dropdown) stop working because their wrapper elements are no longer there.

    Is jqxForm intended to be initialized only once per element, or is reinitializing it multiple times supported?

    2. jqxWindow lifecycle (initialize once vs recreate per open)
    What is the recommended pattern for jqxWindow?

    Should a jqxWindow instance be created once and reused (open/close repeatedly)?

    Or is it considered safe/normal to destroy and recreate the jqxWindow every time the modal is opened?

    If destroying/recreating is supported, is there any guidance on when to prefer that over reusing a single instance?

    3. Dynamic fields inside jqxForm
    If I want to replace the contents of a single form field (for example, inject a different widget depending on a selection), is there an officially supported way to do that without rebuilding the entire form?

    4. Resetting form state between opens
    When reusing the same jqxForm instance inside a jqxWindow, I’ve noticed that values and disabled states persist between opens unless I reset them manually.

    Is manually resetting the form state (clearing values, re-enabling fields, etc.) the expected approach when reusing a jqxForm, or is there a built‑in pattern for this?

    I’m trying to follow best practices and avoid fighting the framework, so any guidance on the intended lifecycle for jqxForm + jqxWindow would be really helpful.

    Happy to share more details or code examples if needed.

    Thanks!


    admin
    Keymaster

    Hi Tattoo,

    jqxForm reinitialization (initialize once vs multiple times) – jqxForm is intended to be initialized once per element. Reinitialization is not a supported lifecycle.

    Why this happens:
    – Calling $(el).jqxForm({…}) rebuilds the internal DOM every time
    – Any widgets you manually created inside the form are destroyed
    – jqxForm does not track or reinitialize child widgets you add yourself

    Recommended pattern:
    – Initialize jqxForm exactly once
    – After that, only:
    – set values
    – enable / disable fields
    – show / hide fields
    – update data via val(), getComponentByName(), etc.

    Avoid calling jqxForm() again unless you fully intend to destroy everything inside it.

    jqxWindow lifecycle (reuse vs recreate) – Create the jqxWindow once and reuse it by opening/closing.

    Example:

    $("#myWindow").jqxWindow({ autoOpen: false });
    
    $("#myWindow").jqxWindow("open");
    $("#myWindow").jqxWindow("close");

    Why reuse is preferred:
    – jqxWindow maintains positioning, modal overlay, and event bindings
    – Recreating it repeatedly:
    – costs more DOM work
    – risks leaked handlers
    – complicates cleanup of child widgets

    When destroy/recreate is reasonable:
    – The structure of the content changes radically
    – You want a completely clean widget tree every time
    – The modal is opened infrequently and complexity is low

    If you do recreate:
    $(“#myWindow”).jqxWindow(“destroy”);
    Then recreate the window, form, and all widgets inside.

    Dynamic fields inside jqxForm (swapping widgets) – There is no officially supported API to replace a field’s widget type dynamically.

    Supported approaches:

    Best practice (recommended):
    – Define all possible field variants up front
    – Toggle visibility or enablement instead of replacing DOM

    Example:
    – text input
    – number input
    – dropdown

    Then switch by hiding/showing components via getComponentByName().

    Why this works:
    – No DOM rebuild
    – Widgets remain stable
    – jqxForm stays in control of layout

    Advanced / fragile option:
    – Manually inject widgets into a container inside the form
    – You must:
    – destroy the old widget yourself
    – replace DOM
    – initialize the new widget
    – Any jqxForm rebuild will break this

    Not recommended:
    – Recalling jqxForm() to refresh a single field
    – Mutating jqxForm-generated DOM without widget cleanup

    Resetting form state between opens

    Yes, manual reset is the expected approach.

    jqxForm:
    – Does not auto-reset on window close
    – Does not track a default state
    – Persists values, disabled states, and visibility

    Recommended reset pattern:
    – Keep a default data object
    – Reapply it before opening the window

    Example:
    $("#myForm").jqxForm("val", defaultFormData);

    Re-enable fields and clear values explicitly as needed.

    Recommended Pattern

    – jqxWindow: initialize once, open/close repeatedly
    – jqxForm: initialize once, never reinitialize
    – Dynamic fields: predefine all variants, toggle visibility
    – Reset behavior: manually reset on window open

    jqxForm is a layout engine, not a dynamic component framework.

    Once you treat it as stateful and static in structure, most lifecycle issues disappear.

    Best regards,
    Peter Stoev


    Tattoo
    Participant

    Thanks for the detailed explanation — this really helps clarify how jqxForm and jqxWindow are intended to be used. Your breakdown of the initialization lifecycle, dynamic field limitations, and reset expectations aligns with what we’re doing on our side, and it explains the behavior we were seeing after the API changes.

    We’ll stick to the recommended pattern of initializing the form and window once, resetting state manually, and being careful with dynamic widget injection. Appreciate the guidance and the clarity.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.