input-is-empty
v0.0.4
Published
Sets boolean data attribute if field is empty
Downloads
3
Readme
input-is-empty
Sets boolean data attribute if field is empty.
Why?
Being a void element, an <input>
element is considered empty by the HTML definition of "empty", since the content model of all void elements is always empty. So they will always match the :empty
pseudo-class, whether or not they have a value. This is also why their value is represented by an attribute in the start tag, rather than text content within start and end tags.
Install
$ npm install input-is-empty
Usage
import InputIsEmpty from 'input-is-empty';
const htmlInputElement = document.querySelector('input-selector');
new InputIsEmpty(htmlInputElement, {/* options */});
Note: Default is
change
Event
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form accept-charset="utf-8">
<input type="" name="">
</form>
<script type="module">
import InputIsEmpty from 'input-is-empty';
const htmlInputElement = document.querySelector('input');
new InputIsEmpty(htmlInputElement);
</script>
</body>
</html>
Options
event
Type: String
Default: change
Description: Event at which the boolean date attribute value will change