vee-validate
vee-validate copied to clipboard
feat: expose controlled values on useForm
What
There is a need where you are only interested in the "controlled" field values, which are fields that have corresponding useField calls. This is a "nice to have" since it improves the form ergonomics, especially for highly generic forms.
This PR introduces controlledValues computed property of the useForm return object, which can be used to only get the controlled values.
const { controlledValues, handleSubmit } = useForm({
initialValues: {
name: 'abc',
createdAt: Date.now(),
};,
});
// `name` is now controlled
useField('name');
const onSubmit = handleSubmit(values => {
// won't have `createdAt` because it is not controlled
console.log(controlledValues.value);
});
Ideally, I would like this exposed in various points in the Form component as a slot prop and also in submission handlers in the submission context. This way it won't affect the current API in any way.
closes #3862
Codecov Report
Merging #3924 (512a5a2) into main (4c59d63) will increase coverage by
0.02%. The diff coverage is100.00%.
@@ Coverage Diff @@
## main #3924 +/- ##
==========================================
+ Coverage 95.88% 95.91% +0.02%
==========================================
Files 68 68
Lines 1992 2006 +14
Branches 514 515 +1
==========================================
+ Hits 1910 1924 +14
Misses 82 82
| Impacted Files | Coverage Δ | |
|---|---|---|
| packages/vee-validate/src/Form.ts | 100.00% <ø> (ø) |
|
| packages/vee-validate/src/useForm.ts | 98.38% <100.00%> (+0.06%) |
:arrow_up: |
:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more
@logaretm works perfectly, that's exactly what I'm looking for to edit and submit forms with GraphQL!.
When are you planning to merge? @logaretm
@logaretm works perfectly, that's exactly what I'm looking for to edit and submit forms with GraphQL!.
When are you planning to merge? @logaretm
@jdinartejesus I was wondering how you will use it with graphql, could you post an example code?
Thank you