Skip to content

Input / select value not set when a-form-item in child component #446

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

Closed
1 task done
kenrose opened this issue Jan 26, 2019 · 4 comments
Closed
1 task done

Input / select value not set when a-form-item in child component #446

kenrose opened this issue Jan 26, 2019 · 4 comments

Comments

@kenrose
Copy link

kenrose commented Jan 26, 2019

  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

1.3.3

Environment

Mac OS X 10.13, Firefox / Chome

Reproduction link

Edit on CodeSandbox

Steps to reproduce

  1. Define a form using the new v-decorator API
  2. Inside the form, reference a child component that defines a-form-items.

That is, the component structure looks like:

<a-form :form="form">
<ChildComponent />
</a-form>

ChildComponent looks like:

<div>
<a-form-item>
<a-select v-decorator="['name']" :options="..." />
</a-form-item>
</div>

There's a full reproduction with CodeSandbox.

What is expected?

If you select a value from the a-select, that value renders correctly.

What is actually happening?

Selecting the a-select does not render the value.

Inspecting the a-select with vue-devtools shows that value == undefined.

Interestingly, if you submit the form, the value from a-select does appear in values after calling form.validateFields.


Old API

This behaviour worked correctly with the old fieldDecoratorId and fieldDecoratorOptions API. That's also shown in the reproduction.

Background

We use this technique of nesting a-form-items in child components to support a UI where there are different parameters required depending on the initial type someone selects. e.g.,

Select Role (options = [Employee, Manager])

If the user picks "Employee", we want things like name, date of birth, etc.
If they select "Manager", we want a very different set of parameters.

We model this as a component for each set of custom arguments.

@kenrose kenrose changed the title Component value not set when a-form-item in child component Input / select value not set when a-form-item in child component Jan 26, 2019
@kenrose
Copy link
Author

kenrose commented Jan 26, 2019

I've tried replacing a-select with a-input and the behaviour is identical to #392.

@tangjinzhou
Copy link
Member

tangjinzhou commented Jan 27, 2019

Now you can use this.$refs.childComponent.$forceUpdate() in beforeUpdate to update children.

And in the next version, we will solve it.

@kenrose
Copy link
Author

kenrose commented Jan 27, 2019

The forceUpdate workaround works. Thank you for the quick response @tangjinzhou.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants