0.6.0 • Published 2 years ago

react-input-feedback v0.6.0

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

React Input Feedback

React Final Form compatible form field component that shows a provided error message

Usage

import React from 'react'
import { InputFeedback } from 'react-input-feedback'
import { Field, Form } from 'react-final-form'

export default FormComponent(props) {
  return (
    <Form onSubmit={props.submitHandler}>
      {
        ({ handleSubmit }) =>
          (
            <form onSubmit={handleSubmit}>
              <p>
                <label>
                  Label: <Field component={InputFeedback} name="input" />
                </label>
              </p>
            </form>
          )
      }
    </Form>
  )
}

With render callback:

import React from 'react'
import { InputFeedback } from 'react-input-feedback'
import { Field, Form } from 'react-final-form'

import MyError from './my-error'
import MyInput from './my-input'

function render(props) {
  return (
    <InputFeedback {...props}>
      {
        ({ error, getErrorProps, getInputProps }) => (
          <React.Fragment>
            <MyInput {...getInputProps({ className: 'input' })} />
            {
              error && (
                <MyError {...getErrorProps({ className: 'error' })}>
                  {error}
                </MyError>
              )
            }
          </React.Fragment>
        )
      }
    </InputFeedback>
  )
}

export default function FormComponent(props) {
  return (
    <Form onSubmit={props.submitHandler}>
      {
        ({ handleSubmit }) =>
          (
            <form onSubmit={handleSubmit}>
              <p>
                <label>
                  Label:
                  <Field name="input" render={render} />
                </label>
              </p>
            </form>
          )
      }
    </Form>
  )
}

Legal

Copyright © 2017-2019 Reidar Djupvik

Licensed under the MIT license. See the LICENSE file for details.

0.6.0

2 years ago

0.5.2

4 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago