vaadin / proposal-for-vaadin-form

Small and fast framework-agnostic library for creating forms with Web Components
Apache License 2.0
9 stars 0 forks source link

Limiting and debouncing validators #13

Open vlukashov opened 5 years ago

vlukashov commented 5 years ago

field-validation

import {VaadinForm, onBlur} from '@vaadin/vaadin-form';

const form = new VaadinForm();
// init the form

const isAvailableName = async (value) => {
  const response = await fetch(`/validate/name/${encodeURIComponent(value)}`);
  const result = await response.json();
  if (result.error) {
    return `Please pick another name. '${value}' is not available.`;
  }
};

form.username.validator = [onBlur(isAvailableName)];