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

Default form values do not show #284

Open
ophirKatz opened this issue Nov 23, 2022 · 6 comments
Open

Default form values do not show #284

ophirKatz opened this issue Nov 23, 2022 · 6 comments
Labels
flag: can be closed? This issue or PR should probably be closed now

Comments

@ophirKatz
Copy link

ophirKatz commented Nov 23, 2022

Hi :)
Trying out the demo app, setting a default value for the FormControl does not appear to affect the UI (the input is empty).
Repro: in astromech-droid.component, set toolCount form control to: new UntypedFormControl(10, { validators: [Validators.required] }),.
This is the result in the UI (notice the 'Number of tools carried' property is empty):
image

Is this behavior OK? How can I set default (and valid) values in the form.
The effect, by the way, is that without editing the form by hand, there are no values attached to the form value.
Thanks in advance.

@maxime1992
Copy link
Contributor

Hello,

I just investigated this because indeed, it should definitely behave as you thought it should and have the default value.

It took me a solid 5mn to realize that this is actually only an issue with the old API and that it works as expected with the new API :)

The demo shows by default the old/deprecated API (we really need to remove it soon...). But instead if you go to /rewrite/listings/new you'll that it behaves as expected:

image

@maxime1992 maxime1992 added the flag: can be closed? This issue or PR should probably be closed now label Nov 23, 2022
@ophirKatz
Copy link
Author

Hi, thanks!
I'm still having a problem with the form value being null until the form is dirty (in the demo as well), which means that although the default values of the form controls are shown, they are not reflected by the root form's output.
Spare your thoughts on this?

@maxime1992
Copy link
Contributor

Umh I guess it makes sense. Sub forms only broadcast their status if they're valid. It's a tough choice between having sub form values always up to date but possibly in an unwanted state, or always have them in an expected state, meaning that updates on a sub form that makes it invalid aren't propagated up (but the form status should be invalid!).

So you could check if the root form is invalid (or even just the control of the sub form you're working with) and if it's invalid assume that it may be out of date for the value

@ophirKatz
Copy link
Author

That's actually not what I meant.
The sub-form controls are valid (assume the default values I provided are valid), but the control of the root form that points to the sub-form is null by default (no other logical value because it's the responsibility of the sub-form to fill that out).
In this case, the value of the form will not be automatically emitted, and the root form is considered invalid.

@maxime1992
Copy link
Contributor

Can you provide a step by step repro please? With every possible details you've got. I'm not sure I understand

@ophirKatz
Copy link
Author

Yep. I'll work on one next week and share it.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flag: can be closed? This issue or PR should probably be closed now
Projects
None yet
Development

No branches or pull requests

2 participants