Skip to content

Add name config option for form field submission in config-only mode - #10

Closed
BrijeshSajeev with Copilot wants to merge 1 commit into
masterfrom
copilot/fix-x-selectra-no-form-field-name
Closed

Add name config option for form field submission in config-only mode#10
BrijeshSajeev with Copilot wants to merge 1 commit into
masterfrom
copilot/fix-x-selectra-no-form-field-name

Conversation

Copilot AI commented Mar 9, 2026

Copy link
Copy Markdown

When x-selectra is used without a native <select> or <input> inside (config-only mode), _sourceEl is null and no value is submitted with forms.

Adds a name config option that auto-creates a hidden <input> for form submission.

Changes

  • selectize.js: Add name: null to DEFAULTS. In config-only init, create a hidden input with the configured name, sync initial value from pre-selected items, and track via _createdHiddenInput flag. Clean up in destroy().
  • index.d.ts: Add name?: string | null to SelectraConfig
  • README.md / src-alpine/README.md: Document in config table

Usage

<div x-data="selectra({ name: 'country', options: [...] })" x-selectra></div>

This creates <input type="hidden" name="country"> inside the wrapper, kept in sync via the existing _syncSourceElement() path.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI changed the title [WIP] Fix x-selectra block missing form field name Add name config option for form field submission in config-only mode Mar 9, 2026
 - 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.
@BrijeshSajeev
BrijeshSajeev force-pushed the copilot/fix-x-selectra-no-form-field-name branch from ac35681 to 4e0fdb1 Compare March 9, 2026 06:53
@BrijeshSajeev BrijeshSajeev added the bug Something isn't working label Mar 9, 2026
@BrijeshSajeev
BrijeshSajeev deleted the copilot/fix-x-selectra-no-form-field-name branch March 9, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants