-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(text-input): validation attrs (#2606)
* feat(text-input): validation attrs * fix(text-input): formStateRestor * style: whitespace * fix(text-input): update elements/pf-text-input/pf-text-input.ts Co-authored-by: Ivana Rodriguez <55894965+eyevana@users.noreply.github.com> * docs: update elements/pf-text-input/demo/validation.html Co-authored-by: Ivana Rodriguez <55894965+eyevana@users.noreply.github.com> --------- Co-authored-by: Ivana Rodriguez <55894965+eyevana@users.noreply.github.com>
- Loading branch information
1 parent
a194ba7
commit 2c019ac
Showing
4 changed files
with
95 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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,14 @@ | ||
--- | ||
"@patternfly/elements": minor | ||
--- | ||
`<pf-text-input>`: adds `helper-text`, `error-text`, and `validate-on` attributes. Forwards `pattern` attribute | ||
|
||
```html | ||
<pf-text-input id="validated" | ||
error-text="Enter a three digit integer" | ||
helper-text="How much wood could a woodchuck chuck?" | ||
validate-on="blur" | ||
pattern="\d{3}" | ||
required></pf-text-input> | ||
<pf-button id="validate">Validate</pf-button> | ||
``` |
This file contains 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,26 @@ | ||
<fieldset> | ||
<legend>Invalid</legend> | ||
<label>Validate on Blur? <pf-switch id="onblur"></pf-switch></label> | ||
<pf-text-input id="validated" | ||
error-text="Enter a three digit integer" | ||
pattern="\d{3}" | ||
required></pf-text-input> | ||
<pf-button id="validate">Validate</pf-button> | ||
</fieldset> | ||
|
||
<script type="module"> | ||
import '@patternfly/elements/pf-button/pf-button.js'; | ||
import '@patternfly/elements/pf-switch/pf-switch.js'; | ||
import '@patternfly/elements/pf-text-input/pf-text-input.js'; | ||
const onblur = document.getElementById('onblur'); | ||
const input = document.getElementById('validated'); | ||
const validate = document.getElementById('validate'); | ||
onblur.addEventListener('change', function() { | ||
validated.validateOn = this.checked ? 'blur' : null; | ||
}); | ||
validate.addEventListener('click', function() { | ||
validated.checkValidity(); | ||
}); | ||
</script> | ||
|
||
<link rel="stylesheet" href="demo.css"> |
This file contains 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 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