-
Notifications
You must be signed in to change notification settings - Fork 3.2k
docs(select): add helperText and errorText section #4029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5804325
docs(select): add helperText and errorText section
thetaPC c0ff5e0
fix(select): add missing import, labels, and placeholders
thetaPC 463f095
chore(select): use dev build
thetaPC f68f7a1
refactor(select): match Angular validation
thetaPC b3a6640
fix(select): use correct value
thetaPC d1c5d6a
Update static/usage/v8/select/helper-error/index.md
thetaPC fd05ff2
Update static/usage/v8/select/helper-error/angular/example_component_…
thetaPC 37e475e
Update static/usage/v8/select/helper-error/demo.html
thetaPC f7c6cd7
Update static/usage/v8/select/helper-error/react.md
thetaPC 92692bb
Update static/usage/v8/select/helper-error/vue.md
thetaPC de91fae
Update static/usage/v8/select/helper-error/javascript.md
thetaPC 1ea1e12
chore(select): run lint
thetaPC 4cf78af
chore(select): remove dev build
thetaPC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "dependencies": { | ||
| "@ionic/core": "8.4.1", | ||
| "@ionic/core": "8.4.4-dev.11741289071.1e8e1c3f", | ||
| "ionicons": "7.4.0" | ||
| } | ||
| } |
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
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
19 changes: 19 additions & 0 deletions
19
static/usage/v8/select/helper-error/angular/example_component_html.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| ```html | ||
| <form [formGroup]="myForm" (ngSubmit)="onSubmit()"> | ||
| <ion-select | ||
| formControlName="favFruit" | ||
| label="Default label" | ||
| placeholder="Favorite Fruit" | ||
| helperText="Select your favorite fruit" | ||
| errorText="This field is required" | ||
| > | ||
| <ion-select-option value="apple">Apple</ion-select-option> | ||
| <ion-select-option value="banana">Banana</ion-select-option> | ||
| <ion-select-option value="orange">Orange</ion-select-option> | ||
| </ion-select> | ||
|
|
||
| <br /> | ||
|
|
||
| <ion-button type="submit" size="small">Submit</ion-button> | ||
| </form> | ||
| ``` | ||
29 changes: 29 additions & 0 deletions
29
static/usage/v8/select/helper-error/angular/example_component_ts.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| ```ts | ||
| import { Component } from '@angular/core'; | ||
| import { FormBuilder, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms'; | ||
| import { IonSelect, IonSelectOption, IonButton } from '@ionic/angular/standalone'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-example', | ||
| standalone: true, | ||
| imports: [IonSelect, IonSelectOption, IonButton, ReactiveFormsModule], | ||
| templateUrl: './example.component.html', | ||
| styleUrl: './example.component.css', | ||
| }) | ||
| export class ExampleComponent { | ||
| myForm: FormGroup; | ||
|
|
||
| constructor(private fb: FormBuilder) { | ||
| this.myForm = this.fb.group({ | ||
| favFruit: ['', Validators.required], | ||
| }); | ||
| } | ||
|
|
||
| onSubmit() { | ||
| // Mark the control as touched to trigger the error message. | ||
| // This is needed if the user submits the form without interacting | ||
| // with the select. | ||
| this.myForm.get('favFruit')!.markAsTouched(); | ||
| } | ||
| } | ||
| ``` |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Input</title> | ||
| <link rel="stylesheet" href="../../common.css" /> | ||
| <script src="../../common.js"></script> | ||
| <script | ||
| type="module" | ||
| src="https://cdn.jsdelivr.net/npm/@ionic/core@8.4.4-dev.11741289071.1e8e1c3f/dist/ionic/ionic.esm.js" | ||
| ></script> | ||
| <link | ||
| rel="stylesheet" | ||
| href="https://cdn.jsdelivr.net/npm/@ionic/core@8.4.4-dev.11741289071.1e8e1c3f/css/ionic.bundle.css" | ||
| /> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div class="container"> | ||
| <form id="my-form"> | ||
| <ion-select | ||
| label="Default label" | ||
| placeholder="Favorite Fruit" | ||
thetaPC marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| helper-text="Select your favorite fruit" | ||
| error-text="This field is required" | ||
| > | ||
| <ion-select-option value="apple">Apple</ion-select-option> | ||
| <ion-select-option value="banana">Banana</ion-select-option> | ||
| <ion-select-option value="orange">Orange</ion-select-option> | ||
| </ion-select> | ||
|
|
||
| <br /> | ||
|
|
||
| <ion-button type="submit" size="small">Submit</ion-button> | ||
| </form> | ||
| </div> | ||
|
|
||
| <script> | ||
| const form = document.getElementById('my-form'); | ||
| const favFruit = form.querySelector('ion-select'); | ||
|
|
||
| form.addEventListener('submit', (event) => submit(event)); | ||
| favFruit.addEventListener('ionChange', (event) => validateSelect(event)); | ||
| favFruit.addEventListener('ionBlur', () => onIonBlur({ detail: { value: favFruit.value } })); | ||
|
|
||
| const validateSelect = (event) => { | ||
| if (!event.detail.value) { | ||
| favFruit.classList.add('ion-invalid'); | ||
| favFruit.classList.remove('ion-valid'); | ||
| } else { | ||
| favFruit.classList.remove('ion-invalid'); | ||
| favFruit.classList.add('ion-valid'); | ||
| } | ||
| }; | ||
|
|
||
| const markTouched = () => { | ||
| favFruit.classList.add('ion-touched'); | ||
| }; | ||
|
|
||
| const onIonBlur = (event) => { | ||
| markTouched(); | ||
| validateSelect(event); | ||
| }; | ||
|
|
||
| const submit = (event) => { | ||
| event.preventDefault(); | ||
|
|
||
| markTouched(); | ||
| validateSelect({ detail: { value: favFruit.value } }); | ||
| }; | ||
| </script> | ||
| </body> | ||
| </html> | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import Playground from '@site/src/components/global/Playground'; | ||
|
|
||
| import javascript from './javascript.md'; | ||
| import react from './react.md'; | ||
| import vue from './vue.md'; | ||
|
|
||
| import angular_example_component_html from './angular/example_component_html.md'; | ||
| import angular_example_component_ts from './angular/example_component_ts.md'; | ||
|
|
||
| <Playground | ||
| version="8" | ||
| code={{ | ||
thetaPC marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| javascript, | ||
| react, | ||
| vue, | ||
| angular: { | ||
| files: { | ||
| 'src/app/example.component.html': angular_example_component_html, | ||
| 'src/app/example.component.ts': angular_example_component_ts, | ||
| }, | ||
| }, | ||
| }} | ||
| src="usage/v8/select/helper-error/demo.html" | ||
| /> | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| ```html | ||
| <form id="my-form"> | ||
| <ion-select | ||
| label="Default label" | ||
| placeholder="Favorite Fruit" | ||
thetaPC marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| helper-text="Select your favorite fruit" | ||
| error-text="This field is required" | ||
| > | ||
| <ion-select-option value="apple">Apple</ion-select-option> | ||
| <ion-select-option value="banana">Banana</ion-select-option> | ||
| <ion-select-option value="orange">Orange</ion-select-option> | ||
| </ion-select> | ||
|
|
||
| <br /> | ||
|
|
||
| <ion-button type="submit" size="small">Submit</ion-button> | ||
| </form> | ||
|
|
||
| <script> | ||
| const form = document.getElementById('my-form'); | ||
| const favFruit = form.querySelector('ion-select'); | ||
|
|
||
| form.addEventListener('submit', (event) => submit(event)); | ||
| favFruit.addEventListener('ionChange', (event) => validateSelect(event)); | ||
| favFruit.addEventListener('ionBlur', () => onIonBlur({ detail: { value: favFruit.value } })); | ||
|
|
||
| const validateSelect = (event) => { | ||
| if (!event.detail.value) { | ||
| favFruit.classList.add('ion-invalid'); | ||
| favFruit.classList.remove('ion-valid'); | ||
| } else { | ||
| favFruit.classList.remove('ion-invalid'); | ||
| favFruit.classList.add('ion-valid'); | ||
| } | ||
| }; | ||
|
|
||
| const markTouched = () => { | ||
| favFruit.classList.add('ion-touched'); | ||
| }; | ||
|
|
||
| const onIonBlur = (event) => { | ||
| markTouched(); | ||
| validateSelect(event); | ||
| }; | ||
|
|
||
| const submit = (event) => { | ||
| event.preventDefault(); | ||
|
|
||
| markTouched(); | ||
| validateSelect({ detail: { value: favFruit.value } }); | ||
| }; | ||
| </script> | ||
| ``` | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| ```tsx | ||
| import React, { useRef, useState } from 'react'; | ||
| import { IonSelect, IonSelectOption, IonButton, SelectCustomEvent } from '@ionic/react'; | ||
|
|
||
| function Example() { | ||
| const [isTouched, setIsTouched] = useState<boolean>(false); | ||
| const [isValid, setIsValid] = useState<boolean | undefined>(); | ||
|
|
||
| const favFruitRef = useRef<HTMLIonSelectElement>(null); | ||
|
|
||
| const validateSelect = (event: SelectCustomEvent<{ value: string }>) => { | ||
| setIsValid(event.detail.value ? true : false); | ||
| }; | ||
|
|
||
| const markTouched = () => { | ||
| setIsTouched(true); | ||
| }; | ||
|
|
||
| const onIonBlur = () => { | ||
| markTouched(); | ||
|
|
||
| if (favFruitRef.current) { | ||
| validateSelect({ detail: { value: favFruitRef.current.value } } as SelectCustomEvent<{ | ||
| value: string; | ||
| }>); | ||
| } | ||
| }; | ||
|
|
||
| const submit = (event: React.FormEvent<HTMLFormElement>) => { | ||
| event.preventDefault(); | ||
|
|
||
| markTouched(); | ||
|
|
||
| if (favFruitRef.current) { | ||
| validateSelect({ detail: { value: favFruitRef.current.value } } as SelectCustomEvent<{ | ||
| value: string; | ||
| }>); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <form onSubmit={submit}> | ||
| <IonSelect | ||
| ref={favFruitRef} | ||
| label="Default label" | ||
| placeholder="Favorite Fruit" | ||
thetaPC marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| className={`${isValid ? 'ion-valid' : ''} ${isValid === false ? 'ion-invalid' : ''} ${ | ||
| isTouched ? 'ion-touched' : '' | ||
| }`} | ||
| helperText="Select your favorite fruit" | ||
| errorText="This field is required" | ||
| onIonChange={(event) => validateSelect(event)} | ||
| onIonBlur={onIonBlur} | ||
| > | ||
| <IonSelectOption value="apple">Apple</IonSelectOption> | ||
| <IonSelectOption value="banana">Banana</IonSelectOption> | ||
| <IonSelectOption value="orange">Orange</IonSelectOption> | ||
| </IonSelect> | ||
|
|
||
| <br /> | ||
|
|
||
| <IonButton type="submit" size="small"> | ||
| Submit | ||
| </IonButton> | ||
| </form> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| export default Example; | ||
| ``` | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.