Skip to content

Latest commit

 

History

History
77 lines (53 loc) · 1.72 KB

README.md

File metadata and controls

77 lines (53 loc) · 1.72 KB

Emails input library

emails-input is a pure js library to generate an input for multiple emails in your application.

Check out the demo here

How to use

  1. Add the emails-input library (you can find the latest version in dist/bundle.js)
<script src="emails-input.js"></script>
  1. Add a container element somewhere in your applicatoin
<div id="emails-input"></div>
  1. Initialize the component
var inputContainerNode = document.querySelector('#emails-input');
var emailsInput = EmailsInput(inputContainerNode);

Full example:

<div id="emails-input"></div>
<script src="emails-input.js"></script>
<script>
  const containerNode = document.querySelector('#emails-input');
  const emailsInput = EmailsInput(containerNode);
</script>

Available methods

.addEmail(email)

Adds a new email with the provided text to the input.

const emailsInput = EmailsInput(containerNode);
emailsInput.addEmail('[email protected]');

.deleteEmail(email)

Deletes an email with the provided text from the input.

const emailsInput = EmailsInput(containerNode);
emailsInput.deleteEmail('[email protected]');

.deleteLastEmail()

Deletes the last email in the input. No action is done if no emails are found.

const emailsInput = EmailsInput(containerNode);
emailsInput.deleteLastEmail();

.getValidEmails()

Returns an array with the list of valid emails in the input.

const emailsInput = EmailsInput(containerNode);
const validEmails = emailsInput.getValidEmails();
console.log(validEmails.length);
// 2