From 13d2d115d44f109c3ea2a47bcb518c6090126325 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Tue, 16 May 2023 09:50:56 -0400 Subject: [PATCH] fix(select): modern syntax works with forms (#27480) Issue number: resolves #27478 --------- ## What is the current behavior? The modern syntax render function was missing `renderHiddenInput` which caused modern `ion-select` instances to not participate in form submission. Legacy syntax is not affected. ## What is the new behavior? - Modern syntax calls `renderHiddenInput`. ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information Dev build: `7.0.7-dev.11684158250.1920157d` --- core/src/components/select/select.tsx | 4 +++- .../components/select/test/select.spec.tsx | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 core/src/components/select/test/select.spec.tsx diff --git a/core/src/components/select/select.tsx b/core/src/components/select/select.tsx index 8f51db99e1..f55ddac853 100644 --- a/core/src/components/select/select.tsx +++ b/core/src/components/select/select.tsx @@ -745,7 +745,7 @@ export class Select implements ComponentInterface { } private renderSelect() { - const { disabled, el, isExpanded, labelPlacement, justify, placeholder, fill, shape } = this; + const { disabled, el, isExpanded, labelPlacement, justify, placeholder, fill, shape, name, value } = this; const mode = getIonMode(this); const hasFloatingOrStackedLabel = labelPlacement === 'floating' || labelPlacement === 'stacked'; const justifyEnabled = !hasFloatingOrStackedLabel; @@ -753,6 +753,8 @@ export class Select implements ComponentInterface { const inItem = hostContext('ion-item', this.el); const shouldRenderHighlight = mode === 'md' && fill !== 'outline' && !inItem; + renderHiddenInput(true, el, name, parseValue(value), disabled); + return ( { + it('should render hidden input for form validation', async () => { + const page = await newSpecPage({ + components: [Select], + template: () => , + }); + + const select = page.body.querySelector('ion-select'); + + const hiddenInput = select.querySelector('input[type="hidden"]'); + expect(hiddenInput).not.toBe(null); + + expect(hiddenInput.value).toBe('my value'); + expect(hiddenInput.disabled).toBe(true); + expect(hiddenInput.name).toBe('my name'); + }); +});