Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@bedrockstreaming/form-validation-rule-list
Advanced tools
This utility package allows to add a visual validation feedback to your users. It exposes a Higher Order Component that helps displaying a list of rules with 3 possible states for each one: default, incomplete, complete
This utility package allows to add a visual validation feedback to your users. It exposes a Higher Order Component that helps displaying a list of rules with 3 possible states for each one: default, incomplete, complete
By default, you can already validate your forms without adding any other library to the mix. It is also very trivial to display some error message since every dictionary component are receiving it from props. So why would you need something like form validation rule list
? To give your users some hints about what is going wrong with their typing. It's too often that we apply several validations rules on a single input and many of those rules are complaining at the same time, then what to display ?
npm install @bedrockstreaming/form-validation-rule-list
Extra validation
const extraValidation = {
oneUpperCaseCharacter: () => (fieldValue) => /(?=.*[A-Z])/.test(fieldValue),
minLength: (minLengthValue) => (fieldValue) =>
fieldValue && fieldValue.length >= minLengthValue,
};
Schema
const schema = {
fields: {
password: {
id: 'password',
type: 'password',
validation: {
oneUpperCaseCharacter: {
key: 'oneUpperCaseCharacter',
message: 'You need at least one upper cased character',
},
minLength: {
key: 'minLength',
message: 'You password should be minimum 12 characters long',
value: 12,
},
},
},
},
steps: {...},
stepsById: [...]
};
Dictionary
import {
getValidationRulesHints,
checkRules,
withValidationRuleList,
} from '@bedrockstreaming/form-validation-rule-list';
import { PasswordTextField } from '@mylib/textfield';
import { RuleList } from '@mylib/rule-list';
const ValidatedPasswordTextField = withValidationRuleList(PasswordTextField);
const dictionary = {
password: ({ errors, validation, label, ...props }) => {
// These rules don't match react-hook-form's rule API, its proper to the form-validation-rule-list package
const rules = getValidationRulesHints({
errors,
validation,
});
const hasError = !!checkRules(props.value, rules).length;
const fieldError = errors && errors.type;
const isValid = !!(props.value && !hasError && !fieldError);
return (
<div>
<ValidatedPasswordTextField
label={label}
hasError={hasError}
valid={isValid}
{...props}
// specific props required by ValidationRuleList
rules={rules}
ruleComponent={RuleList}
/>
</div>
);
},
};
:warning: Beware, you can't use several react-hook-form
default rules as validation hints since the errors
object returned by the library can only contain one default rule error at a time.
Run nx test form-validation-rule-list
to execute the unit tests via Jest.
FAQs
This utility package allows to add a visual validation feedback to your users. It exposes a Higher Order Component that helps displaying a list of rules with 3 possible states for each one: default, incomplete, complete
The npm package @bedrockstreaming/form-validation-rule-list receives a total of 1 weekly downloads. As such, @bedrockstreaming/form-validation-rule-list popularity was classified as not popular.
We found that @bedrockstreaming/form-validation-rule-list demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.