final-form-set-errors-mutator
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "final-form-set-errors-mutator", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Mutator for setting errors outside of form (for example in redux-saga)", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
# final-form-set-errors-mutator | ||
Mutator for setting errors outside of form (for example in redux-saga) | ||
# Installation | ||
```bush | ||
npm install final-form-set-errors-mutator | ||
``` | ||
# How to use | ||
@@ -12,3 +18,2 @@ | ||
import { setErrors } from "final-form-set-errors-mutator"; | ||
import { TextField } from "mui-fields"; | ||
import { ModelState } from "model-state-validation"; | ||
@@ -23,3 +28,3 @@ | ||
const MyForm: FunctionComponent<Props> = (props) => { | ||
const [formApi, setFormApi] = useState<FormApi>(null); | ||
const [ formApi, setFormApi ] = useState<FormApi>(null); | ||
@@ -29,6 +34,6 @@ const formSubscription: FormSubscription = { | ||
}; | ||
const [password, setPassword] = useState<string>(""); | ||
const [confirmPassword, setConfirmPassword] = useState<string>(""); | ||
const [ password, setPassword ] = useState<string>(""); | ||
const [ confirmPassword, setConfirmPassword ] = useState<string>(""); | ||
const handleChangePassword = (event: ChangeEvent<HTMLInputElement>) => { | ||
@@ -51,3 +56,3 @@ const modelState = new ModelState(); | ||
modelState.addError( | ||
"confirmPassword", | ||
"confirm-password", | ||
"Passwords are not equals." | ||
@@ -74,14 +79,20 @@ ); | ||
<form onSubmit={handleSubmit}> | ||
<Field | ||
name={"password"} | ||
component={TextField} | ||
type="password" | ||
onChange={handleChangePassword} | ||
/> | ||
<Field | ||
name={"confirm-password"} | ||
component={TextField} | ||
type="password" | ||
onChange={handleChangeConfirmPassword} | ||
/> | ||
<Field name="password"> | ||
{({ input, meta }) => ( | ||
<div> | ||
<label>Password</label> | ||
<input {...input} type="text" placeholder="Password" onChange={handleChangePassword}/> | ||
{meta.error && meta.touched && <span>{meta.error}</span>} | ||
</div> | ||
)} | ||
</Field> | ||
<Field name="confirm-password"> | ||
{({ input, meta }) => ( | ||
<div> | ||
<label>Confirm your password</label> | ||
<input {...input} type="password" placeholder="Confirm password" onChange={handleChangeConfirmPassword}/> | ||
{meta.error && meta.touched && <span>{meta.error}</span>} | ||
</div> | ||
)} | ||
</Field> | ||
</form> | ||
@@ -95,3 +106,2 @@ ); | ||
export { MyForm }; | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6225
102