wotamann / vuetify-form-base

Schema-based Form Generator - Vue.js 2.0 Component based on Vuetify 2.0
https://wotamann.github.io/vuetify
231 stars 63 forks source link

fromCtrl and toCtrl not changing the model #43

Closed jorgv closed 4 years ago

jorgv commented 4 years ago

Hello,

I am trying to sync two fields, so the second field can use the value of the first one:


    email: {
      type: 'text',
      label: 'Email',
      rules: [rules.email],
    },
    username: {
      type: 'text',
      label: 'Username',
      readonly: true,
      toCtrl: ({ data }) => data && data.email,
      fromCtrl: ({ data }) => data && data.email,
    },
}

on the ui, the value is change whenever email field is modified, but when the form is submitted the username model value is empty.

Is there other way I can synchronize the fields or this is a bug?

using: "vuetify": "2.3.4", "vuetify-form-base": "^0.1.22",

thanks

wotamann commented 4 years ago

Hi,

Schema Property 'TOCTRL' provides the ability to set/modify the visible value of your Control. What you wanted is to change not only the visible value but also the data behind it.

Try this

username: {
          type: 'text',
          label: 'Username',
          readonly:true,
          toCtrl: ({  data }) => { data.username = data.email; return data.username},          
        }
jorgv commented 4 years ago

thank it works as expected!

thanks for this great plugin