umer936/multi-emails-input

There is no license information available for the latest version (v1.1) of this package.

multi-emails-input is a small library to convert a div into a multiple emails input

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 1

Language:JavaScript

v1.1 2024-03-21 21:04 UTC

This package is auto-updated.

Last update: 2024-05-21 21:32:18 UTC


README

multi-emails-input is a small library to convert a div into a multiple emails input, basically if you have any div and you want to convert it into a multi emails input this lib is best to do that.

This lib is written in pure JavaScript and could be converted to an npm package if needed.

How to use?

You can start by adding the JavaScript file into html.

<script src="<PATH_TO_LIB>/emails-input.js"></script>

Also add the CSS file into your head tag

<link rel="stylesheet" src="<PATH_TO_LIB>/emails-input.css" />

You can wrap your div selector with the provided function as follow:

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

This will convert the normal div into a multi emails input container.

68747470733a2f2f692e696d6775722e636f6d2f4a523744485a7a2e676966

Features

  • Email block can be created by pressing Enter, entering comma , , or by losing focus on the input field blur event.
  • A Block can be deleted by the X sign in each block.
  • Pasted emails will be converted into blocks immediately. (e.g., “max@mail.ru, ivan@mail.ru”) they should be converted into multiple blocks.
  • Invalid emails are not added to the returned list.
  • Duplicated emails have different style to expose them and can be deleted.
  • EmailsInput function as shown in the example above returns an object of 2
    • getEmailsList: an function that returns an array of valid emails as shown in the element.
    • addEmail: a function that you can send an email and it will be added to the list.
  • all code has JSDOC provided that should help in types.
  • library is tested and is working fine on all browsers including ie11.

Options

  • limitEmailsToDomain: is an option to define what email is valid and what is not so for example if you provided this option as gmail then any email other than gmail will be considered as invalid.
  • invalidEmailClass: is an option to provide a different class for the invalid emails that overrides the default style in case the user needs to.
  • validEmailClass: is an option to provide a different class for the valid emails same as the invalid one.
  • Example:
const emailsInput = EmailsInput(inputContainerNode, {
  limitEmailsToDomain: 'gmail',
  invalidEmailClass: 'custom-invalid-email',
  validEmailClass: 'custom-valid-email',
});