Skip to content

Allow external value #5016

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

Open
intellild opened this issue Apr 1, 2025 · 1 comment
Open

Allow external value #5016

intellild opened this issue Apr 1, 2025 · 1 comment

Comments

@intellild
Copy link

intellild commented Apr 1, 2025

Is your feature request related to a problem? Please describe.

I have a complex form with realtime preview on the left. The real data is stored model, with two view-models two-way binded to the model. useForm only support deep copy data from initialValue.

Image

Describe the solution you'd like

Allow two-way binding from external value.

const model = reactive({ realValue: 'opt1-opt2' });

const formViewModel = reactive({
  field1: computed({
    get() {
      return model.realValue.split('-')[0];
    },
    set(value) {
      model.realValue = value + '-' + model.realValue.split('-')[1];
    },
  }),
  field2: computed({
    get() {
      return model.realValue.split('-')[1];
    },
    set(value) {
      model.realValue = model.realValue.split('-')[1] + '-' + value;
    },
  }),
});

const form = useForm({ values: formViewModel }); // all edits are synced to `model`

Describe alternatives you've considered

All these model, view-models are in different shape, so it is really a bad idea to use data from the form for preview

@intellild
Copy link
Author

intellild commented Apr 1, 2025

The real scenario is more complex, the model is ouside of vue and 'computed' to another framework data, for example, some chart library. There could be multiple frameworks constructs the preview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant