Skip to content

Instantly share code, notes, and snippets.

@alonbardavid
Created September 2, 2019 11:47
Show Gist options
  • Save alonbardavid/93e0c05980c9a795e0426e1c27925423 to your computer and use it in GitHub Desktop.
Save alonbardavid/93e0c05980c9a795e0426e1c27925423 to your computer and use it in GitHub Desktop.
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