Last active
September 8, 2016 13:09
-
-
Save puiutucutu/1d197f1afcda0bba7903ec15a8e5da04 to your computer and use it in GitHub Desktop.
Foundation 6 Abide cleanup with named attributes and dataset interfaces
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
// check if form element has attributes using getNamedItem() on the attributes interface | |
if (trailerDetailsFormSection['type'].attributes.getNamedItem('required')) { | |
// remove named attribute also using the attributes interface via removeNamedItem(); | |
trailerDetailsFormSection['type'].attributes.removeNamedItem('required'); | |
} | |
// ... and is equivalent to running | |
// see https://lists.w3.org/Archives/Public/www-dom/2001JanMar/0094.html for explanation | |
trailerDetailsFormSection['type'].removeAttribute('required'); | |
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
/** | |
* @param el | |
*/ | |
function cleanupFoundationAbideAttributes(el) { | |
// cleanup element (which appears as `data-invalid` in DOM) | |
if (el.dataset.invalid === '') { | |
delete el.dataset.invalid; | |
} | |
// cleanup element (alternate method) | |
if (el.attributes.getNamedItem('data-invalid')) { | |
el.attributes.removeNamedItem('data-invalid'); | |
} | |
// cleanup input | |
if (el.classList.contains('is-invalid-input')) { | |
el.classList.remove('is-invalid-input'); | |
} | |
// cleanup label | |
if (el.parentNode.classList.contains('is-invalid-label')) { | |
el.parentNode.classList.remove('is-invalid-input'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment