Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

true-value and false-value are ignored on initial render #2694

Closed
kas84 opened this issue Nov 30, 2020 · 9 comments
Closed

true-value and false-value are ignored on initial render #2694

kas84 opened this issue Nov 30, 2020 · 9 comments
Labels
🐞 bug Something isn't working scope: v-model

Comments

@kas84
Copy link

kas84 commented Nov 30, 2020

Version

3.0.3

Reproduction link

https://codesandbox.io/s/hopeful-zhukovsky-yuxqi?file=/src/App.vue

Steps to reproduce

<template>
  <label>model {{model}}</label>
  <input type="checkbox" v-model="model" :true-value="false" :false-value="true" />
</template>

<script>
import {ref} from 'vue'
export default {
  name: 'App',
  setup(){
    const model=ref(false)
    return {
      model
    }
  }
}
</script>

What is expected?

checkbox expected to be checked since model is false and true-value="false"

What is actually happening?

checkbox is not checked on first render


After you click it once, it actually works okay.

@edison1105
Copy link
Member

edison1105 commented Dec 1, 2020

I opened a PR,but I found that true-value and false-value are also not supported when v-model value is a Set or an Array.Is it designed like this?

@posva
Copy link
Member

posva commented Dec 1, 2020

@edison1105 yes, that's normal. With sets and arrays, there should be a value attribute instead

@edison1105
Copy link
Member

@edison1105 yes, that's normal. With sets and arrays, there should be a value attribute instead

Got it,Thanks~

@posva posva changed the title true-value and false-value not working properly true-value and false-value not working when they are inverted Dec 1, 2020
@edison1105
Copy link
Member

Hi @posva
I think this is not about inverted value. see https://codesandbox.io/s/fast-worker-k8q0e?file=/src/App.vue
I modified the code to see the problem more clearly.

@posva posva changed the title true-value and false-value not working when they are inverted true-value and false-value not working when they respectively false and truthy Dec 1, 2020
@edison1105
Copy link
Member

Because true-value or false-value is not assigned to the checkbox after first rendered.

image

@posva posva changed the title true-value and false-value not working when they respectively false and truthy true-value and false-value are ignored on initial render Dec 1, 2020
@posva posva added 🐞 bug Something isn't working scope: v-model labels Dec 1, 2020
@edison1105
Copy link
Member

I think 48f00c0 is not fix this bug.

We should assign true-value or false-value to checkbox but setChecked is not do this after first render.

<div id="app">
  <label>model {{ model }}</label>
  <input type="checkbox" v-model="model" :true-value="11" :false-value="22" />
</div>

<script>
  const { ref,createApp } = Vue
  createApp({
    name: "App",
    setup() {
      const model = ref(false);
      return {
        model,
      };
    },
  }).mount('#app')
</script>

After first render,the model value is still false not 22.
image

And my PR is make it works fine.

@edison1105
Copy link
Member

Hi @posva @yyx990803
I update demo https://codesandbox.io/s/fast-worker-k8q0e?file=/src/App.vue with lastest vue-next version 3.0.4.
This bug still happens.I think the model value should be 22 on initial render.

@yyx990803
Copy link
Member

model should be the source of truth, not the template. If the user intends to provide an initial value that is neither true-value or false-value, the value should be left untouched.

This actually has nothing to do with true/false-value. e.g. if you have <input type="checkbox" v-model="model"> but model's initial value is 123, it will not be changed to false.

@edison1105
Copy link
Member

model should be the source of truth, not the template. If the user intends to provide an initial value that is neither true-value or false-value, the value should be left untouched.

This actually has nothing to do with true/false-value. e.g. if you have <input type="checkbox" v-model="model"> but model's initial value is 123, it will not be changed to false.

OK

@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐞 bug Something isn't working scope: v-model
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants