This package has been deprecated

Author message:

This package has been moved to @w0s/form-control-validation

@saekitominaga/htmlformcontrolelement-validation
TypeScript icon, indicating that this package has built-in type declarations

2.0.4 • Public • Published

Input validation of form control

npm version test status

Demo

Examples

<script type="module">
import FormControlValidation from './dist/FormControlValidation.js';

for (const formControlElement of document.querySelectorAll('.js-validation')) {
  const formControlValidation = new FormControlValidation(formControlElement);
  formControlValidation.init();
}
</script>

<!-- input -->
<p><input class="js-validation" pattern="[a-zA-Z0-9]+"
  aria-errormessage="validation-input"
  data-validation-message-pattern="Only alphanumeric characters can be used."
/></p>
<p hidden="" id="validation-input"></p>

<!-- radio buttons -->
<p role="radiogroup" class="js-validation" aria-errormessage="validation-radio">
<label><input type="radio" required="" />Radio 1</label>
<label><input type="radio" required="" />Radio 2</label>
</p>
<p hidden="" id="validation-radio"></p>

<!-- select -->
<p><select class="js-validation" required="" aria-errormessage="validation-select">
<option label="Please select"></option>
<option value="1">Select 1</option>
<option value="2">Select 2</option>
</select></p>
<p hidden="" id="validation-select"></p>

<!-- textarea -->
<p><textarea class="js-validation"
  aria-errormessage="validation-textarea"></textarea></p>
<p hidden="" id="validation-textarea"></p>

Constructor

new FormControlValidation(
  thisElement: HTMLElement
)

Parameters

thisElement [required]
Target element

HTMLElement Attributes

aria-errormessage [required]
ID of the element that displays the validation message. See WAI-ARIA 1.2 for details.
data-validation-message-pattern [optional]
Error message when it does not match the pattern attribute value. If omitted, the default message of the browser is displayed.

Readme

Keywords

none

Package Sidebar

Install

npm i @saekitominaga/htmlformcontrolelement-validation

Weekly Downloads

2

Version

2.0.4

License

MIT

Unpacked Size

46.8 kB

Total Files

7

Last publish

Collaborators

  • saekitominaga