All Projects β†’ github β†’ Auto Check Element

github / Auto Check Element

Licence: mit
An input element that validates its value with a server endpoint.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Auto Check Element

Use Custom Element
Custom hook to bridge Custom Elements (Web Components) to React.
Stars: ✭ 77 (-9.41%)
Mutual labels:  web-components, custom-elements
Vanilla Colorful
A tiny color picker custom element for modern web apps (2.7 KB) 🎨
Stars: ✭ 467 (+449.41%)
Mutual labels:  web-components, custom-elements
Include Fragment Element
A client-side includes tag.
Stars: ✭ 380 (+347.06%)
Mutual labels:  web-components, custom-elements
Three Elements
Web Components-powered custom HTML elements for building Three.js-powered games and interactive experiences. πŸŽ‰
Stars: ✭ 331 (+289.41%)
Mutual labels:  web-components, custom-elements
Task Lists Element
Drag and drop task list items.
Stars: ✭ 73 (-14.12%)
Mutual labels:  web-components, custom-elements
Monogatari
Monogatari is a simple web visual novel engine, created to bring Visual Novels to the web.
Stars: ✭ 357 (+320%)
Mutual labels:  web-components, custom-elements
Details Menu Element
A menu opened with <details>.
Stars: ✭ 455 (+435.29%)
Mutual labels:  web-components, custom-elements
storify
Instagram/Whatsapp stories clone built on Web Components and Web Animations API. πŸ”₯
Stars: ✭ 64 (-24.71%)
Mutual labels:  web-components, custom-elements
Emoji Picker Element
A lightweight emoji picker for the modern web
Stars: ✭ 587 (+590.59%)
Mutual labels:  web-components, custom-elements
Dark Mode Toggle
A custom element that allows you to easily put a Dark Mode πŸŒ’ toggle or switch on your site:
Stars: ✭ 550 (+547.06%)
Mutual labels:  web-components, custom-elements
Synergy
Synergy is a tiny runtime library for building web user interfaces
Stars: ✭ 296 (+248.24%)
Mutual labels:  web-components, custom-elements
Details Dialog Element
A modal dialog that's opened with <details>.
Stars: ✭ 603 (+609.41%)
Mutual labels:  web-components, custom-elements
Weightless
High-quality web components with a small footprint
Stars: ✭ 284 (+234.12%)
Mutual labels:  web-components, custom-elements
Custom Elements Ts
Create native custom elements using Typescript
Stars: ✭ 52 (-38.82%)
Mutual labels:  web-components, custom-elements
anywhere-webcomponents
A UI work in progress based on custom elements (web components) for use in anywhere.
Stars: ✭ 17 (-80%)
Mutual labels:  web-components, custom-elements
Lume
Create CSS3D/WebGL applications declaratively with HTML. Give regular DOM elements shadow and lighting.
Stars: ✭ 445 (+423.53%)
Mutual labels:  web-components, custom-elements
bui
β€Ήbβ€Ί Web components for creating applications – built by Blackstone Publishing using lit-html and lit-element
Stars: ✭ 29 (-65.88%)
Mutual labels:  web-components, custom-elements
svelte-webcomponents
A ready-to-use project template to build custom elements (web components) with Svelte 3 with support and examples for web components, jest, sass, nested components with props, eslinting, stylelinting, Github actions, propagating custom events from shadow-DOM to real-DOM etc.
Stars: ✭ 22 (-74.12%)
Mutual labels:  web-components, custom-elements
Remount
Mount React components to the DOM using custom elements
Stars: ✭ 522 (+514.12%)
Mutual labels:  web-components, custom-elements
Xy Ui
πŸŽ¨ι’ε‘ζœͺζ₯ηš„εŽŸη”Ÿ web components UIη»„δ»ΆεΊ“
Stars: ✭ 603 (+609.41%)
Mutual labels:  web-components, custom-elements

<auto-check> element

An input element that validates its value against a server endpoint.

Installation

$ npm install --save @github/auto-check-element

Usage

Script

Import as a modules:

import '@github/auto-check-element'

With a script tag:

<script type="module" src="./node_modules/@github/auto-check-element/dist/index.js">

Markup

<auto-check src="/signup-check/username" csrf="<%= authenticity_token_for("/signup-check/username") %>">
  <input>
</auto-check>

Note that in the following example the CSRF element is marked with the data-csrf attribute rather than name so that the value doesn't get posted to the backend when the element is placed in a form.

<auto-check src="/signup-check/username">
  <input>
  <input hidden data-csrf value="<%= authenticity_token_for("/signup-check/username") %>">
</auto-check>

Attributes

  • src is the server endpoint that will receive POST requests. The posted form contains a value parameter containing the text input to validate. Responding with a 200 OK status indicates the provided value is valid. Any other error status response indicates the provided value is invalid.
  • csrf is the CSRF token for the posted form. It's available in the request body as a authenticity_token form parameter.
    • You can also supply the CSRF token via a child element. See usage example.
  • required is a boolean attribute that requires the validation to succeed before the surrounding form may be submitted.

Events

Network request lifecycle events

Request lifecycle events are dispatched on the <auto-check> element. These events do not bubble.

  • loadstart - The server fetch has started.
  • load - The network request completed successfully.
  • error - The network request failed.
  • loadend - The network request has completed.

Network events are useful for displaying progress states while the request is in-flight.

const check = document.querySelector('auto-check')
const container = check.parentElement
check.addEventListener('loadstart', () => container.classList.add('is-loading'))
check.addEventListener('loadend', () => container.classList.remove('is-loading'))
check.addEventListener('load', () => container.classList.add('is-success'))
check.addEventListener('error', () => container.classList.add('is-error'))

Auto-check events

auto-check-start is dispatched on when there has been input in the element. In event.detail you can find:

  • setValidity: A function to provide a custom failure message on the input. By default it is 'Verifying…'.
const input = check.querySelector('input')

input.addEventListener('auto-check-start', function(event) {
  const {setValidity} = event.detail
  setValidity('Loading validation')
})

auto-check-send is dispatched before the network request begins. In event.detail you can find:

  • body: The FormData request body to modify before the request is sent.
const input = check.querySelector('input')

input.addEventListener('auto-check-send', function(event) {
  const {body} = event.detail
  body.append('custom_form_data', 'value')
})

auto-check-success is dispatched when the server responds with 200 OK. In event.detail you can find:

  • response: The successful server Response. Its body can be used for displaying server-provided messages.
input.addEventListener('auto-check-success', async function(event) {
  const message = await event.detail.response.text()
  console.log('Validation passed', message)
})

auto-check-error is dispatched when the server responds with a 400 or 500 range error status. In event.detail you can find:

  • response: The failed server Response. Its body can be used for displaying server-provided messages.
  • setValidity: A function to provide a custom failure message on the input. By default it is 'Validation failed'.
input.addEventListener('auto-check-error', async function(event) {
  const {response, setValidity} = event.detail

  setValidity('Validation failed')

  const message = await response.text()
  console.log('Validation failed', message)
})

auto-check-complete is dispatched after either the success or error events to indicate the end of the auto-check lifecycle.

input.addEventListener('auto-check-complete', function(event) {
  console.log('Validation complete', event)
})

Browser support

Browsers without native custom element support require a polyfill.

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge

Development

npm install
npm test

License

Distributed under the MIT license. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].