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

Setting values #26

Open
timdeschryver opened this issue Nov 3, 2023 · 5 comments
Open

Setting values #26

timdeschryver opened this issue Nov 3, 2023 · 5 comments

Comments

@timdeschryver
Copy link
Owner

timdeschryver commented Nov 3, 2023

We should support an API to update/set/patch the current value and/or controls of a form.
This is already supported for form fields, but not for form groups.

@michael-small
Copy link
Contributor

michael-small commented Mar 25, 2024

Do you have an idea for the API surface, of a set for starters? That is what I would think would be the first method to base things off of. Control values as WritableSignal<Value> naturally can be .set(...), but with form groups being Signal<UnwrappedFormGroup<Fields>>, then I imagine some method would be exposed on the group itself.

Provided I am correct in that assumption,
A) What would you name the setter?
B) Would the setter essentially just map the field values with whatever nesting level of the controls?

In my head it would be like

  form = createFormGroup<{ name: string; age: number | null }>({
    name: 'Alice',
    age: null,
  });

  someMethodThatSetsValue() {
    // Verbose name, but I imagine `.set()` would be confusing since it isn't a `WritableSignal`
    this.form.setFormGroupValue({ name: 'Jerry', age: 20 })
  }

@timdeschryver
Copy link
Owner Author

That seems good to me @michael-small !
For naming, I like the simplicity of set to be honest, but I'm also fine with setFormGroupValue.

@michael-small
Copy link
Contributor

michael-small commented Mar 26, 2024

That seems good to me @michael-small !

I'll take a look into this approach then.

For naming, I like the simplicity of set to be honest, but I'm also fine with setFormGroupValue.

For the time being with my attempt I'll just start with the more verbose phrasing and if I actually get an implementation going then I suppose we would re-evaluate. Interested in hearing from anyone else reading this, since we are 1 vs 1 leaning on one solution but open to the other (minus the fact you are the owner and I am just some random person lol).

Edit: as an aside, it was nice to hear about this library referenced at different times at ng-conf this year. @timdeschryver did you hear some of the news/buzz on forms from the conference? Edit 2: or, were you there and I didn't see you?

@timdeschryver
Copy link
Owner Author

Oh cool, that's nice to hear. I wasn't at ng-conf and I wasn't aware that it was talked about in the hallway.

@michael-small
Copy link
Contributor

michael-small commented Mar 27, 2024

Update on this issue: I have a somewhat working version of the group setter going. I think it is rather naive and missing some things, but it is coming along. I am comparing it with a reactive form on the same page with the form group filler and individual control prefills. I'm sure of course the assumptions are a bit different, I'll probably have questions on that later.

Aside about ng-conf: Yeah, ng-conf was nice. There was a lot of discussion about forms. It seems like all of the attempts to integrate forms with signals, a mix of template and reactive forms like this library, is what it sounds like to me that some people are speculating is the future. That's what I got from random chatter and gossip, and probably a lot of my bias in interpreting it. One of my favorite questions from the Q&A was about the future of forms. It sounds like the more immediate plan is to "bolt on" signals to the existing API, and then the future of the forms API is quite up for discussion and under wraps until then.

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

2 participants