Releases: github/auto-check-element
v5.0.2
v5.0.1
v5.0.0
A lot of changes! We've completely re-written parts of the component.
- Make sure we emit a loading state outside the debounced function (#35)
- Set the required property correctly when the attribute changes (#39)
- Add hooks so that the consuming application can set validation messages (#37)
- Set credentials as
same-origin
in fetch options for older browsers (#36) - Use
AbortController
to cancel inflight requests (#32) - Use
@github/mini-throttle
for debouncing (#33) - Replace XHR request implementation with fetch (#29)
v4.1.1
v4.1.0
4.1.0
v4.0.2
4.0.2
<auto-check> element
An input element that validates its value against a server endpoint.
Installation
$ npm install --save @github/auto-check-element
Usage
import '@github/auto-check-element'
<auto-check src="/signup_check/username" csrf="<%= authenticity_token_for("/signup_check/username") %>">
<input>
</auto-check>
Provide a URL and a CSRF token and the autocheck component will show validation confirmations and validation errors.
The endpoint should respond to POST requests with:
- a 200 HTTP status code if the provided value if valid.
- a 422 HTTP status code if the provided value is invalid.
- a optional error message in the body and a
Content-Type
header with a value oftext/html; fragment
.
Events
const check = document.querySelector('auto-check')
// Network request lifecycle events.
check.addEventListener('loadstart', function(event) {
console.log('Network request started', event)
})
check.addEventListener('loadend', function(event) {
console.log('Network request complete', event)
})
check.addEventListener('load', function(event) {
console.log('Network request succeeded', event)
})
check.addEventListener('error', function(event) {
console.log('Network request failed', event)
})
// Auto-check result events.
const input = check.querySelector('input')
input.addEventListener('auto-check-send', function(event) {
console.log('Adding to FormData before network request is sent.')
const {body} = event.detail
body.append('custom_form_data', 'value')
})
input.addEventListener('auto-check-success', function(event) {
const {message} = event.detail
console.log('Validation passed', message)
})
input.addEventListener('auto-check-error', function(event) {
const {message} = event.detail
console.log('Validation failed', message)
})
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.
v4.0.1
4.0.1
<auto-check> element
An input element that validates its value against a server endpoint.
Installation
$ npm install --save @github/auto-check-element
Usage
import '@github/auto-check-element'
<auto-check src="/signup_check/username" csrf="<%= authenticity_token_for("/signup_check/username") %>">
<input>
</auto-check>
Provide a URL and a CSRF token and the autocheck component will show validation confirmations and validation errors.
The endpoint should respond to POST requests with:
- a 200 HTTP status code if the provided value if valid.
- a 422 HTTP status code if the provided value is invalid.
- a optional error message in the body and a
Content-Type
header with a value oftext/html; fragment
.
Events
const check = document.querySelector('auto-check')
// Network request lifecycle events.
check.addEventListener('loadstart', function(event) {
console.log('Network request started', event)
})
check.addEventListener('loadend', function(event) {
console.log('Network request complete', event)
})
check.addEventListener('load', function(event) {
console.log('Network request succeeded', event)
})
check.addEventListener('error', function(event) {
console.log('Network request failed', event)
})
// Auto-check result events.
const input = check.querySelector('input')
input.addEventListener('auto-check-send', function(event) {
console.log('Adding to FormData before network request is sent.')
const {body} = event.detail
body.append('custom_form_data', 'value')
})
input.addEventListener('auto-check-success', function(event) {
const {message} = event.detail
console.log('Validation passed', message)
})
input.addEventListener('auto-check-error', function(event) {
const {message} = event.detail
console.log('Validation failed', message)
})
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.