compose-form-up
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -31,3 +31,3 @@ // Dependencies | ||
Event.on( document, 'blur', '[required]', checkValidation ) | ||
Event.on( document, 'keydown', '[required]', Event.debounce( checkValidation, 200 ) ) | ||
Event.on( document, 'input', '[required]', Event.debounce( checkValidation, 200 ) ) | ||
@@ -40,3 +40,3 @@ } | ||
// Scoped variables | ||
var invalidInput = form.querySelector( 'input:invalid, textarea:invalid' ) | ||
var invalidInput = form.querySelector( 'input:invalid, textarea:invalid, select:invalid' ) | ||
@@ -80,3 +80,3 @@ // The form is valid, skip it | ||
valid = isValid( input ), | ||
neutral = !valid && event == 'keydown'; | ||
neutral = !valid && event == 'input'; | ||
@@ -83,0 +83,0 @@ // Don't trigger invalid style while typing |
{ | ||
"name": "compose-form-up", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A lightweight HTML5 form validation utility", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -26,13 +26,13 @@ var assert = require('chai').assert | ||
addInput: function( form, options ) { | ||
addInput: function( form, options, tag ) { | ||
options = options || {} | ||
tag = tag || '<input type="text">' | ||
defaults = { | ||
required: true, | ||
type: 'text' | ||
} | ||
var label = Utils.injectHTML( form, '<label></label>' ) | ||
var input = Utils.injectHTML( label, '<input>' ) | ||
var input = Utils.injectHTML( label, tag ) | ||
@@ -55,2 +55,13 @@ for ( var attr in defaults ) { input.setAttribute( attr, defaults[attr] ) } | ||
selectOption: function( select, index ) { | ||
select.selectedIndex = index | ||
// Shabby test code justification: It's really hard to trigger events in tests, so this | ||
// short circuits the system. It's not ideal but for now | ||
// it'll do. | ||
select.parentNode.classList.toggle( 'invalid', !select.checkValidity() ) | ||
select.parentNode.classList.toggle( 'valid', select.checkValidity() ) | ||
}, | ||
isValid: function( input ) { | ||
@@ -57,0 +68,0 @@ assert.isTrue( input.checkValidity() == true && input.parentNode.classList.contains( 'valid' ) ) |
@@ -8,2 +8,3 @@ | ||
setValue = utils.setValue, | ||
selectOption = utils.selectOption, | ||
Event = require( 'compose-event' ) | ||
@@ -98,2 +99,15 @@ | ||
it( 'tests select elements', function() { | ||
var select = utils.addInput( fieldsetOne, {}, '<select><option value="">Select something</option><option value="1">Something</option></select>') | ||
utils.submit( form ) | ||
isInvalid( select ) | ||
selectOption( select, 1 ) | ||
isValid( select ) | ||
fieldsetOne.removeChild( fieldsetOne.lastChild ) | ||
}) | ||
}) | ||
@@ -100,0 +114,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
19991
431
0