UNPKG

@encoreskytech/char-limit-hint

Version:

To initialize the char limit feature on text input

1 lines 864 B
Node.prototype.charLimit=function(a){if("TEXTAREA"!==this.nodeName&&"INPUT"!==this.nodeName){var b=document.createElement("span");return b.classList.add("invalid-element"),b.innerText="Only input element is allowed",this.after(b),0}if("textarea"!==this.type&&"text"!==this.type){var c=document.createElement("span");return c.classList.add("invalid-element-type"),c.innerText="Only text and textarea input type is allowed",this.after(c),0}var d=document.createElement("span");d.classList.add("char-limit-hint"),d.innerText=a+" characters remaining",this.after(d),this.maxLength=a,this.addEventListener("keyup",function(b){var c=a-b.target.value.length;d.innerHTML=c+" characters remaining"},!0)};var NodeCharElement=null;"undefined"==typeof exports?NodeCharElement=document.querySelector.bind(document):exports.NodeCharElement=document.querySelector.bind(document);