Import the emails input script file. Call the EmailsInput
function with HtmlElement or collection of elements which should contain the emails input.
const emailsInput = EmailsInput(inputContainerNode, options);
interface EmailInputOptions {
value: string | string[];
}
Value could be a string with an email or comma separated emails or array of such strings. Examples of supported values:
'iafanasov@hotmail.com'
'iafanasov@hotmail.com,iafanasov@outlook.com'
' iafanasov@hotmail.com , iafanasov@outlook.com '
[' iafanasov@hotmail.com , iafanasov@outlook.com ']
[' iafanasov@hotmail.com , iafanasov@outlook.com ', null]
[' iafanasov@hotmail.com , iafanasov@outlook.com ', 'iafanasov@gmail.com']
The EmailsInput function call return the object with the following API
export interface EmailInputAPI {
/** Adds the email
* @param email a string with an email or comma separated emails or array of such strings
*/
add: (email: string | string[]) => void;
/** @returns array with all the valid entered emails */
getValidEmails: () => string[];
}
const inputContainerNode = document.querySelector('#emails-input');
const emailsInput = EmailsInput(inputContainerNode, {value: [' iafanasov@hotmail.com , trololo ', 'iafanasov@gmail.com']});
const inputContainerNodes = document.querySelectorAll('.my-emails-input');
inputContainerNodes.forEach(function (elem) {
EmailsInput(elem);
})
package.json
contains all the information and commands necessary for the further development.