
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
final-form-set-errors-mutator
Advanced tools
Mutator for setting errors outside of form (for example in redux-saga)
Mutator for setting form errors.
It allows you validate your form values outside of form (for example in redux-saga).
npm install final-form-set-errors-mutator
Add to form
import { FormApi } from "final-form";
import React, { FunctionComponent } from "react";
import { Form, Field } from "react-final-form";
import { setErrors } from "final-form-set-errors-mutator";
import { ModelState } from "model-state-validation";
interface PasswordModel {
password: string;
confirmPassword: string;
}
interface IMyFormProps {
submit: (model: PasswordModel, formApi: FormApi) => void;
}
const MyForm: FunctionComponent<IMyFormProps> = ({ submit }) => {
return (
<Form
onSubmit={submit}
mutators={[ setErrors ]}
>
{({ handleSubmit }) => {
return (
<form onSubmit={handleSubmit}>
<Field name="password">
{({ input, meta }) => (
<div>
<label>Password</label>
<input {...input} type="password"/>
{meta.error && meta.touched && <span>{meta.error}</span>}
</div>
)}
</Field>
<Field name="confirmPassword">
{({ input, meta }) => (
<div>
<label>Confirm your password</label>
<input {...input} type="password"/>
{meta.error && meta.touched && <span>{meta.error}</span>}
</div>
)}
</Field>
</form>
);
}}
</Form>
);
};
function* mySaga(action) {
const { model, formApi } = action.payload;
const modelState = validate(model);
formApi.mutators.setErrors(modelState);
if (modelState.isValid()) {
// api request or something else
}
}
function validate(model: PasswordModel): ModelState {
const modelState = new ModelState();
if (model.password !== model.confirmPassword) {
modelState.addError(
"confirmPassword",
"Passwords are not equals."
);
}
return modelState;
}
FAQs
Mutator for setting errors outside of form (for example in redux-saga)
The npm package final-form-set-errors-mutator receives a total of 0 weekly downloads. As such, final-form-set-errors-mutator popularity was classified as not popular.
We found that final-form-set-errors-mutator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.