Skip to content

Add name config option for form field name in x-selectra - #11

Merged
gajendrajena merged 3 commits into
masterfrom
fix-x-selectra-no-form-field-name
Mar 9, 2026
Merged

Add name config option for form field name in x-selectra#11
gajendrajena merged 3 commits into
masterfrom
fix-x-selectra-no-form-field-name

Conversation

@BrijeshSajeev

Copy link
Copy Markdown
Collaborator
  • When x-selectra is used in config-only mode (without a native or element), there was no form field name, making form submission impossible. This adds a name config option that auto-creates a hidden input element for form submission when no source element exists.

Address code review: sync initial value and use flag for auto-created inputs

  • Set initial value on hidden input from pre-selected items

  • Use _createdHiddenInput flag to distinguish auto-created hidden inputs from user-provided ones in destroy()

  • The new feature is the name config option that auto-creates a hidden for form submission when no source element exists add the name usage example to both READMEs and add a demo section to the examples page.

 - When x-selectra is used in config-only mode (without a native <select>
  or <input> element), there was no form field name, making form submission
  impossible. This adds a `name` config option that auto-creates a hidden
  input element for form submission when no source element exists.

Address code review: sync initial value and use flag for auto-created inputs

 - Set initial value on hidden input from pre-selected items
 - Use _createdHiddenInput flag to distinguish auto-created hidden inputs
  from user-provided ones in destroy()

 - The new feature is the name config option that auto-creates a hidden <input> for form submission when no source <select> element exists
 - add the name usage example to both READMEs and add a demo section to the examples page.
…e] tuples:

 - Added `_normalizeOption()` that converts [text, value] array tuples into `{ [labelField]: text, [valueField]: value }` objects.
 - Updated `addOption()` and `_registerOptions()` to normalize array-format options before processing.
 - Added "Array-Format Options" to the features list.
 - Added Demo 9: Array-Format Options.
…a single hidden <input> with a comma-joined value ("118,63,121"), causing the form to submit ["118,63,121"] instead of ["118", "63", "121"].

Fix — 4 changes:

  - Deferred hidden input creation to after mode detection so we know single vs multi
  - `Single mode`: unchanged — one hidden <input> with the selected value
  - `Multi mode`: creates a container with one hidden <input> per selected item via `_syncHiddenInputs()`, so the form submits a proper array `_syncSourceElement` now delegates to `_syncHiddenInputs()` when the container exists, rebuilding the inputs on every item change
  - destroy cleans up the container
@gajendrajena
gajendrajena merged commit 33d8e73 into master Mar 9, 2026
1 check passed
@gajendrajena
gajendrajena deleted the fix-x-selectra-no-form-field-name branch March 9, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants