logaretm / vee-validate

✅ Painless Vue forms
https://vee-validate.logaretm.com/v4
MIT License
10.8k stars 1.26k forks source link

[V4] The value of radio fields is kept by the form even when hidden #3963

Closed anis closed 2 years ago

anis commented 2 years ago

What happened?

The value of a radio field is kept on unmount, even though the option keepValues is set to false. I expect a Form to not keep the value of a hidden radio field.

Reproduction steps

  1. Create a Form with a radio Field:

    <Form>
    <Field type="radio" name="demo" value="1" />
    <Field type="radio" name="demo" value="2" />
    </Form>
  2. After selecting one of the values, hide the Field somehow (by clicking on a button for instance):

    <Field v-if="showField" type="radio" ... />
    ...
    <button @click="showField = false" />
  3. When the Field is unmounted, see how its value is still kept by the Form

Using the demo link you may follow the steps below:

  1. Click on whatever radio button you want ("Yes" or "No")
  2. Type in some text in the textfield
  3. See how the values of both question1 and question2 are displayed
  4. Click on the "Hide the questions" button which hides both fields
  5. See how the value of question2 disappears, but question1 is kept even though the field has been unmounted

Version

Vue.js 3.x and vee-validate 4.x

What browsers are you seeing the problem on?

Relevant log output

No response

Demo link

https://codesandbox.io/embed/vigorous-bohr-dh6uyo?fontsize=14&hidenavigation=1&theme=dark

Code of Conduct

logaretm commented 2 years ago

Thank you for reporting this, I found the issue and will tag a new release shortly.