Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Mar 28, 2019. It is now read-only.

Formik based form samples#1

Open
reinhard wants to merge29 commits intomaster
base:master
Choose a base branch
Loading
fromRP-Feature-forms
Open

Conversation

@reinhard
Copy link
Member

No description provided.

@reinhardreinhard requested a review frommepheserApril 20, 2018 07:18
Copy link
Member

@mephesermepheser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Error handling

// see https://github.com/jaredpalmer/formik/issues/288
const {user, setErrors} = action
if (user.name.startsWith('G')) {
setErrors({name: 'Names starting with \'G\' are not allowed.'})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@reinhard Why not check this directly in Form usingname: yup.string().matches(insertRegexHere).required()?
If this is an example for server side errors: I think these should be treated the "normal" redux way, meaning an FORMS_POST_USER_ERROR action is thrown and reducer saves userPostError.

This userPostRestError may be injected to UserForm and used as "external" error to be added to internal formik errors like

constUserForm=({user, onSubmit, restError}:Props)=>{return(<Formikkey={user.id+user.lastModified.toString()}displayName="UserForm"onSubmit={(values,{setErrors})=>onSubmit(values,setErrors)}initialValues={user}validateOnChange={false}validationSchema={validationSchema}render={({values, errors, touched, setErrors})=>{if(restError){// setErrors(..add external restErrors if present)}return(<Form><FormRowname="name"label="Name"errors={errors}touched={touched}/><FormRowname="email"label="E-Mail"errors={errors}touched={touched}/><AddressesFormvalues={values}errors={errors}touched={touched}/><Boxmt={2}><ButtonLink><Linkto="/forms">Cancel</Link></ButtonLink><buttontype="submit">Save</button>              //  or render "general" rest errors like "internal server error" without binding to a field{(restError)&&<div> Error saving user:{restError}</Box></Form>)}}/>)}

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

1 more reviewer

@mephesermephesermepheser left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@reinhard@mepheser

[8]ページ先頭

©2009-2025 Movatter.jp