Created
September 2, 2019 11:47
-
-
Save alonbardavid/93e0c05980c9a795e0426e1c27925423 to your computer and use it in GitHub Desktop.
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
function myComponent(selector,label,value,onChange,validations = {}){ | |
let element = document.querySelector(selector); | |
element.innerHTML=``` | |
<div class="my-element"> | |
<label>${label}</label> | |
<input></input> | |
</div> | |
``` | |
let input = element.querySelector('input'); | |
input.value = value; | |
if (validations.maxLength) { | |
input.maxLength = validations.maxLength; | |
} | |
if (validations.pattern){ | |
input.pattern = pattern; | |
} | |
input.addEventListener('input',onChange); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment