🌐
PrimeFaces
primefaces.org › primereact-v8 › reactfinalform
React Final Form Integration - PrimeReact
E.g. [email protected]'; } if (!data.password) { errors.password = 'Password is required.'; } if (!data.accept) { errors.accept = 'You need to agree to the terms and conditions.'; } return errors; }; const onSubmit = (data, form) => { setFormData(data); setShowMessage(true); form.restart(); }; const isFormFieldValid = (meta) => !!(meta.touched && meta.error); const getFormErrorMessage = (meta) => { return isFormFieldValid(meta) && <small className="p-error">{meta.error}</small>; }; const dialogFooter = <div className="flex justify-content-center"><Button label="OK" className="p-button-text" au
🌐
PrimeFaces
primefaces.org › primereact-v8 › reacthookform
React Hook Form Integration - PrimeReact
import React, { useEffect, useState } from 'react'; import { useForm, Controller } from 'react-hook-form'; import { InputText } from 'primereact/inputtext'; import { Button } from 'primereact/button'; import { Dropdown } from 'primereact/dropdown'; import { Calendar } from 'primereact/calendar'; import { Password } from 'primereact/password'; import { Checkbox } from 'primereact/checkbox'; import { Dialog } from 'primereact/dialog'; import { Divider } from 'primereact/divider'; import { classNames } from 'primereact/utils'; import { CountryService } from '../service/CountryService'; import './
🌐
DZone
dzone.com › coding › javascript › how to create react js form using hooks and primereact/primefaces ui components
How To Create React JS Form
May 22, 2023 - import React, { useEffect, useState } from 'react'; import { useForm, Controller } from 'react-hook-form'; import { InputText } from 'primereact/inputtext'; import { Button } from 'primereact/button'; import { Dropdown } from 'primereact/dropdown'; import { Calendar } from 'primereact/calendar'; import { Password } from 'primereact/password'; import { Checkbox } from 'primereact/checkbox'; import { Dialog } from 'primereact/dialog'; import { Divider } from 'primereact/divider'; import { classNames } from 'primereact/utils'; import { CountryService } from './CountryService'; import 'primeicons/
🌐
CodeSandbox
codesandbox.io › s › primereact-form-1oxew
PrimeReact form - CodeSandbox
May 25, 2021 - PrimeReact form by gregory-shklover using classnames, json-schema-ref-parser, lodash, primeflex, primeicons, primereact, prop-types, react, react-dom
Published   Apr 26, 2021
Author   gregory-shklover
🌐
C# Corner
c-sharpcorner.com › article › how-to-create-react-js-form-using-hooks-and-primereactprimefaces-ui-components
How To Create React JS Form Using Hooks And PrimeReact/Primefaces UI Components
June 12, 2022 - import React, { useEffect, useState } from 'react'; import { useForm, Controller } from 'react-hook-form'; import { InputText } from 'primereact/inputtext'; import { Button } from 'primereact/button'; import { Dropdown } from 'primereact/dropdown'; import { Calendar } from 'primereact/calendar'; import { Password } from 'primereact/password'; import { Checkbox } from 'primereact/checkbox'; import { Dialog } from 'primereact/dialog'; import { Divider } from 'primereact/divider'; import { classNames } from 'primereact/utils'; import { CountryService } from './CountryService'; import 'primeicons/
🌐
GitHub
github.com › primefaces › primereact-examples
GitHub - primefaces/primereact-examples: PrimeReact Example Projects
PrimeReact team has created various samples to get you started.
Starred by 142 users
Forked by 103 users
Languages   TypeScript 52.3% | JavaScript 22.3% | CSS 19.8% | HTML 4.6% | Astro 1.0% | TypeScript 52.3% | JavaScript 22.3% | CSS 19.8% | HTML 4.6% | Astro 1.0%
🌐
CodeSandbox
codesandbox.io › examples › package › primereact
primereact examples - CodeSandbox
Use this online primereact playground to view and fork primereact example apps and templates on CodeSandbox.
Top answer
1 of 2
4

I have updated this ticket: https://github.com/primefaces/primereact/issues/2547

I think there needs to be showcase example on how to use InputNumber with React Hook Forms if it is not straightforward like you are seeing.

Edit 07/30/2022: I have it working and here are two examples:

Price example must be between 0 and 250,000.

<Controller name="price" control={control} rules={{ required: 'Price is required.', min: 0, max: 250000 }} render={({ field, fieldState }) => (
   <>
      <label htmlFor={field.name} className={classNames({ 'p-error': errors.price })}>Price*</label>
      <InputNumber id={field.name} ref={field.ref} value={field.value} onBlur={field.onBlur} onValueChange={(e) => field.onChange(e)} mode="currency" currency="USD" locale="en-US" inputClassName={classNames({ 'p-invalid': fieldState.error })} />
      {getFormErrorMessage(fieldState)}
  </>
)} />

Year example must be between 1970-2030:

<Controller name="year" control={control} rules={{ required: 'Year is required.', min: 1970, max: 2050 }} render={({ field, fieldState }) => (
  <>
      <label htmlFor={field.name} className={classNames({ 'p-error': errors.year })}>Year*</label>
      <InputNumber id={field.name} ref={field.ref} value={field.value} onBlur={field.onBlur} onValueChange={(e) => field.onChange(e)} useGrouping={false} inputClassName={classNames({ 'p-invalid': fieldState.error })} />
      {getFormErrorMessage(fieldState)}
   </>
)} />
2 of 2
1

I encountered the same issue when working with Primereact InputNumber and Formik.

In my case the reason for unexpected behavior of InputNumber component is primereact custom onChange method of InputNumber:

    onChange?(e: InputNumberChangeParams): void 

    interface InputNumberChangeParams {
        originalEvent: React.SyntheticEvent;
        value: number | null;
    }

(Compared to InputText onChange property: onChange?: ChangeEventHandler<HTMLInputElement> | undefined )

formik.handleChange(e) expects e: React.ChangeEvent<any> which means I can't pass (e: InputNumberChangeParams) to the function. The solution for me was to use another function to handle the change and work only with e.value which is provided by InputNumber onChange method.

    onChange={(e): void => {
      formik.setFieldValue("fieldName", e.value);
    }}
🌐
CodeSandbox
codesandbox.io › s › primereact-forms-03lfk
PrimeReact-Forms - CodeSandbox
December 13, 2019 - PrimeReact-Forms by Atracatrenes using axios, classnames, primeflex, primeicons, primereact, react, react-dom, react-scripts, react-transition-group
Published   Dec 12, 2019
Author   Atracatrenes
Find elsewhere
🌐
PrimeReact
primereact.org › inputtext
PrimeReact | React UI Component Library
Invalid state is displayed using the invalid prop to indicate a failed validation. You can use this style when integrating with form validation libraries.
🌐
Cloudbasha
mern.cb.cloudbasha.com › reactjs › event-handling-and-forms-with-primereact
Event Handling and Forms with PrimeReact - Code Bridge
In this example, the component has a handleClick method that is passed as a prop to the Button component as the onClick event handler. The handleClick method is called when the button is clicked, and it updates the component's state to increment the count. Forms are an essential part of many web applications, and PrimeReact ...
🌐
Medium
amirmustafaofficial.medium.com › prime-react-with-javascript-c969395f14d9
Prime React with Javascript. Introduction: | by Amir Mustafa | Medium
December 28, 2022 - import React, { useState } from 'react'; import { Card } from 'primereact/card'; import { InputText } from 'primereact/inputtext'; import { Button } from 'primereact/button'; const Greet = () => { const [state, setState] = useState({ msg: '' }); return ( <> <div className='grid mt-2' > <div className='col-4'> <Card className='bg-black-alpha-20'> <form> <pre>{state.msg}</pre> <InputText value={state.msg} onChange={(e) => setState({...state, msg: e.target.value})} placeholder='Message'/> <Button label={'Greet'} className="p-button-success ml-2" /> </form> </Card> </div> </div> </> ); }; export default Greet; Press enter or click to view image in full size ·
🌐
GitHub
github.com › primefaces › primereact
GitHub - primefaces/primereact: The Most Complete React UI Component Library · GitHub
See PrimeReact homepage for live showcase and documentation.
Starred by 8.3K users
Forked by 1.2K users
Languages   CSS 59.8% | JavaScript 39.7% | SCSS 0.5%
🌐
Refine
refine.dev › home › blog › how to build › how to build a react admin panel with primereact and refine
How to build a React Admin Panel with PrimeReact and Refine | Refine
July 26, 2023 - The product create page will display a form to create a new product. It will allow users to create a new product by filling the form. For this, we'll use the useForm hook from @refinedev/react-hook-form and the input components from PrimeReact.
🌐
Made with React.js
madewithreactjs.com › primereact
PrimeReact - UI Component Library - Made with React.js
August 15, 2023 - "PrimeReact is a UI library for React featuring a rich set of 80+ components, a theme designer, 400+ ready-to-use UI blocks, various theme alternatives, premium create-react-app templates and professional support.
🌐
GitHub
github.com › primefaces › primereact › issues › 1938
Criticism and Suggestion: PrimeReact Form API · Issue #1938 · primefaces/primereact
April 5, 2021 - No, we just standardize all the input components to use onValueChange, keeping the { originalEvent, value, target } scheme for all the input components that will be supported by the Form API. This includes adding onValueChange to components that do not support it and fixing the mess around value and checked in the Checkbox component, for instance. This way we will be able to create a generic API to make the existing controlled components automagically have its state managed by primereact, this will also work with any component that follows the value, onValueChange, { originalEvent, value, target } scheme on props, including external components that does not belong to primereact.
Author   NathanPB
🌐
Best of JS
bestofjs.org › projects › primereact
Best of JS • PrimeReact
Trends and data about PrimeReact project. PrimeReact is a rich set of open source native components for React.
🌐
GitHub
github.com › primefaces › primereact › issues › 2547
Showcase: More Validation Examples · Issue #2547 · primefaces/primereact
December 23, 2021 - In current example there is no example of a radio-button (group) with react-hook-form. I tried making it with RHF Controller, but it looks like you need a RadioGroup wrapper component which is not straightforward to me how to do. Also InputNumber also needs an example. See: https://stackoverflow.com/questions/71811650/primereact-number-input-field-with-react-hook-form
Author   zouterover