You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`handleSubmit` contains a `withControlled` function that you can use to only submit fields controlled by `useField` or `useFieldModel`. Read the [guide](/guide/composition-api/handling-forms) for more information.
// Only fields declared with `useField` or `useFieldModel` will be printed
561
+
alert(JSON.stringify(values, null, 2));
562
+
});
563
+
</script>
564
+
```
565
+
540
566
<DocTiptitle="Virtual Forms">
541
567
542
568
You can use `handleSubmit` to submit **virtual forms** that may use `form` elements or not. As you may have noticed the snippet above doesn't really care if you are using forms or not.
The form values can be categorized into two categories:
435
+
436
+
- Controlled values: values that have a form input controlling them via `useField` or `<Field />` or via `useFieldModel` model binding.
437
+
- Uncontrolled values: values that are inserted dynamically with `setFieldValue` or inserted initially with initial values.
438
+
439
+
Sometimes you maybe only interested in controlled values. For example, your initial data contains noisy extra properties from your API and you wish to ignore them when submitting them back to your API.
440
+
441
+
When accessing `values` from `useForm` result or the submission handler you get all the values, both controlled and uncontrolled values. To get access to only the controlled values you can use `controlledValues` from the `useForm` result:
Alternatively for less verbosity, you can create handlers with only the controlled values with `handleSubmit.withControlled` which has the same API as `handleSubmit`:
0 commit comments