final-form-focus

WebJar for final-form-focus

Лицензия

Лицензия

MIT
Категории

Категории

ORM Данные
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

final-form-focus
Последняя версия

Последняя версия

1.1.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

final-form-focus
WebJar for final-form-focus
Ссылка на сайт

Ссылка на сайт

https://www.webjars.org
Система контроля версий

Система контроля версий

https://github.com/final-form/final-form-focus

Скачать final-form-focus

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/final-form-focus/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>final-form-focus</artifactId>
    <version>1.1.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/final-form-focus/
implementation 'org.webjars.npm:final-form-focus:1.1.2'
// https://jarcasting.com/artifacts/org.webjars.npm/final-form-focus/
implementation ("org.webjars.npm:final-form-focus:1.1.2")
'org.webjars.npm:final-form-focus:jar:1.1.2'
<dependency org="org.webjars.npm" name="final-form-focus" rev="1.1.2">
  <artifact name="final-form-focus" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='final-form-focus', version='1.1.2')
)
libraryDependencies += "org.webjars.npm" % "final-form-focus" % "1.1.2"
[org.webjars.npm/final-form-focus "1.1.2"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

🏁 Final Form Focus 🧐

NPM Version NPM Downloads Build Status codecov.io styled with prettier

Decorator for 🏁 Final Form that will attempt to apply focus to the first field with an error upon an attempted form submission.


Demo


Installation

npm install --save final-form final-form-focus

or

yarn add final-form final-form-focus

Usage

🏁 Final Form Usage

import { createForm } from 'final-form'
import createDecorator from 'final-form-focus'

// Create Form
const form = createForm({ onSubmit })

// Create Decorator
const decorator = createDecorator()

// Decorate form
const undecorate = decorator(form)

// Use form as normal

🏁 React Final Form Usage

import React from 'react'
import { Form, Field } from 'react-final-form'
import createDecorator from 'final-form-focus'

const focusOnErrors = createDecorator()
...
<Form
  onSubmit={submit}
  decorators={[ focusOnErrors ]} // <--------- 😎
  validate={validate}
  render={({ handleSubmit }) =>
    <form onSubmit={handleSubmit}>

      ... inputs here ...

    </form>
  }
/>

Example

Focus On Error Example

Demonstrates how 🏁 Final Form Focus 🧐 works with 🏁 React Final Form.

API

createDecorator: (getInputs?: GetInputs, findInput?: FindInput) => Decorator

A function that takes an optional function to collect a list of focusable inputs on the page and provides a 🏁 Final Form Decorator that will focus on the top-most input on the page with an error when a form submission fails. If no getInputs parameter is provided, it will use a generic one that will return all inputs that appear in document.forms. If no findInput parameter is provided, it will use a generic one that matches the name attribute of the focusable input with the path in the error object.

getFormInputs: (formName: string) => GetInputs

A GetInputs generator that will narrow the list of inputs down to those contained in the named form, i.e. document.forms[formName].

Types

FocusableInput: { name: string, focus: () => void }

A light abstraction of any input that has a name property and upon which focus() may be called.

GetInputs: () => FocusableInput[]

A function that collects a list of focusable inputs that exist on the page.

FindInput: (FocusableInput[], {}) => ?FocusableInput

A function that returns the first element in a list of focusable inputs that has an error

org.webjars.npm

Final Form

Версии библиотеки

Версия
1.1.2