Q: Global configuration for useField/useForm? #3663
Unanswered
sschneider-ihre-pvs
asked this question in
Q&A
Replies: 1 comment 2 replies
-
The configuration is mostly for components given how messy it is to configure stuff every time in templates. Besides, there is nothing to configure for the composition API aside from But from a re-usability aspect, with the composition API you have plenty of options: You can put the most common configs in an object and re-use as necessary. export const defaultConfig = {
validateOnMount: true,
// other stuff
};
// somewhere in your code
import { defaultConfig } from './whatever';
const field = useField('fieldName', rules, {
...defaultConfig,
// other local config
}) You can build an higher-order function that applies the config over const globalConfig = {
validateOnMount: true
};
export const useFieldWithConfig = (field, rules, config) => {
return useField(field, rules, {
...globalConfig,
...config,
})
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
there is configuration but it is mainly for configuring components.
How do I archive that for a useForm so I don't have to handle all fields manually? For example if I only want to validate on blur
Beta Was this translation helpful? Give feedback.
All reactions