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

Sync URL with nested QueryParamGroup #180

Closed
verfault opened this issue Jan 25, 2021 · 4 comments
Closed

Sync URL with nested QueryParamGroup #180

verfault opened this issue Jan 25, 2021 · 4 comments
Labels
Type: Question If you have questions about using ngqp

Comments

@verfault
Copy link

verfault commented Jan 25, 2021

Hello again!

Example: StackBlitz
Version of "@ngqp/core": "1.0.0"
Version of "@angular/core": "9.1.0"

Question
Could you help me with one deal:

I need to sync nested FormGroups with URI by transforming it into QueryFormGroups but I've no idea how to handle it properly.
Is there a way to add QueryFormGroups in existing QueryFormGroups and still to make it work?

I can't get it how to force my addControlToForm to use QueryParamGroup instead of regular FormGroup


Perhaps, the main things I've already explained by the code and in the code, so that would be quite difficult to explain the problem by text. So I'm sorry that I've done the description of the problem that short.


Thank you!

@verfault verfault added the Type: Question If you have questions about using ngqp label Jan 25, 2021
@Airblader
Copy link
Collaborator

Is there a way to add QueryFormGroups in existing QueryFormGroups and still to make it work?

QueryParamGroup does not support nesting groups into each other, because ultimately that doesn't make sense: the URL is one flat object.

I can't get it how to force my addControlToForm to use QueryParamGroup instead of regular FormGroup

This isn't possible. ngqp models its API after Angular Forms, but they are in no way "interchangeable". In fact, using both an Angular form and ngqp is not really what ngqp was originally intended to be used for (you either want to synchronize to the URL as you type, or have a submit-able form, but not both). See Limitations as well.


It is possible to combine Angular forms and ngqp, though. Unfortunately due to how Angular works there is no really good, smooth way to make that work out of the box. You essentially need to manually hook up the QueryParamGroup and FormGroup and synchronize between the two.

@verfault
Copy link
Author

verfault commented Jan 25, 2021

Okay, got it.
So if I'd like to make a filtering with query params syncing there is no easy way to make that work out of the box, isn't there?


I mean in the context where filtering has some groups of options (which are represented as checboxes) and each group has to be synced with URL depending on controls' values like:

?group1=option1,option2,option3&group2=option2 and so on.

@Airblader
Copy link
Collaborator

So if I'd like to make a filtering with query params syncing

That is essentially exactly what ngqp was designed for – if you want to do this as the user interacts with the form, not only once they submit the form (as is the case with Amazon). For the latter, most of what ngqp does isn't necessary. However, I do understand that ngqp might still provide enough "comfort" that you'd want to be able to use it nonetheless.

I go into a bit more detail on that in my response in #165, which I seem to have forgotten about during my illness. You can see there my thought that a likely way I'd implement this in ngqp is by allowing to turn off the automatic synchronization and provide a trigger instead which you'd have to call from your onSubmit handler.

I also mention there a way this could potentially be achieved already now. I did quickly prototype what that would look like, you can find it here: https://stackblitz.com/edit/angular-ivy-hgjj6l? – I can't promise this works in all cases and scenarios, but you could give it a shot if you wanted to.

@verfault
Copy link
Author

verfault commented Jan 28, 2021

Your example is exactly that I needed.
I've implemented some workarounds around FormGroup to make the filtration either, so from now I have two different ways to solve the problem.

Thank you and get well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question If you have questions about using ngqp
Projects
None yet
Development

No branches or pull requests

2 participants