Last active
August 29, 2015 14:21
-
-
Save devbas/734729ee9fee7b53fe5c to your computer and use it in GitHub Desktop.
Custom action for required attribute in HTML5 Forms
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
document.addEventListener("DOMContentLoaded", function() { | |
var elements = document.getElementsByTagName("INPUT"); | |
for (var i = 0; i < elements.length; i++) { | |
elements[i].oninvalid = function(e) { | |
var start = new Date().getTime(); | |
for(var i = 0; i < e.path.length; i++) { | |
if(e.path[i]['classList']) { | |
var parentClass = jQuery.inArray('postbox-container', e.path[i]['classList']); | |
if(parentClass != -1) { | |
if(e.path[i]['classList'][parentClass]) { | |
var container = jQuery('#postbox-container-2').children().children(); | |
var itemId = e.path[i]['previousElementSibling']; | |
console.log('item id: ', itemId); | |
jQuery(container).css('display', 'none'); | |
//jQuery() | |
} | |
} | |
} | |
} | |
var end = new Date().getTime(); | |
var time = end - start; | |
console.log('Execution time: ', time); | |
//console.log('parent class: ', e.path); | |
var parentClass = jQuery.inArray('document', e.path); | |
//console.log('parent class: ', parentClass); | |
e.target.setCustomValidity(""); | |
if (!e.target.validity.valid) { | |
e.target.setCustomValidity("This field cannot be left blank"); | |
} | |
}; | |
elements[i].oninput = function(e) { | |
e.target.setCustomValidity(""); | |
}; | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment