Add name config option for form field name in x-selectra - #11
Merged
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
nameconfig 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.