logaretm / vee-validate

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

form values will be covered by the `initialValue` value of `usefield` #4846

Open byronogis opened 1 month ago

byronogis commented 1 month ago

What happened?

// component A
// there is already have a form (by useForm), 
const {
  values,
  setValues,
} = useForm()

// and then use setValues to set a new value, 
setValues({
  name: 'x',
})

// component B
// create a new field (by useField, and have a avaliable initialValue y)
const {
  value
} = useField('name', undefined, {
  initialValue: 'y'
})

when the compoent B is dynamic create, the name will y not x

"vee-validate": "^4.13.2",
"vue": "^3.3.11",

Reproduction steps

See https://stackblitz.com/edit/puuk1z-imn8wg?file=src%2FApp.vue,src%2FInputText.vue&startScript=dev

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://stackblitz.com/edit/puuk1z-imn8wg?file=src%2FApp.vue,src%2FInputText.vue&startScript=dev

Code of Conduct

byronogis commented 1 month ago

I carefully checked the record of #3429. Maybe the above situation is an acquiescence behavior?

I am currently adding a optional props forceValuein to Component B for solve current issue.

// component B
// create a new field (by useField, and have a avaliable initialValue y)

const props = defienProps<{
  forceValue?: any
  // ...
}>()

const {
  value
} = useField('name', undefined, {
  initialValue: props.forceValue || 'y'
})