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

Feature: [up-validate] with different URL #486

Open
marc-mabe opened this issue May 9, 2023 · 3 comments
Open

Feature: [up-validate] with different URL #486

marc-mabe opened this issue May 9, 2023 · 3 comments

Comments

@marc-mabe
Copy link

Hi,

It would be very helpful to be able to point up-validate to another URL then the form action (like <form action="/form-result" up-validate up-validate-url="/form-render">).

My use case is as follows:

  • I have a form for performing filtering on a page
  • The form does not get rendered where the filters are getting applied
  • Some form fields needs to get re-loaded (re-rendered) based on other form fields

In more detail it looks like this:

  • User navigates to a page where filters can be applied
  • a backend (symfony) form is used to handle query params
  • clicking on filter-button a drawer with disabled history gets opened using URL where the form gets rendered
  • the form action is the form rendering URL
  • submitting the form will close the current layer onsubmit="up.layer.accept();"
  • the form is setup with up-validate
  • a submit button (outside the form using formaction) is pointing to the page where the form needs to be applied on

Now modifying one form field will trigger up-validate making the form re-render using the form rendering action and submitting the form via the button will close the drawer and send the form to the page where the filter will be applied.

BUT submitting the form differently, like via keyboard, will submit the form rendering page instead.
If I would be able to use a different URL for up-validate only I would not need to use differen form actions in the first place and just tell unpoly to use a different URL for validating (aka re-rendering) the form and the logic would be much more straight forward.

This pattern could also be used to workaround #460

@marc-mabe marc-mabe changed the title Feature: [up-validate] to different action Feature: [up-validate] with different URL May 9, 2023
@triskweline
Copy link
Contributor

I like it. It could be implemented by parsing and merging an { url } option here.

Do you think [up-validate-url] or [up-validate-action] is the more intuitive name here? Arguments can be made for both. The render option is actually { url }, but in an HTML form we use [action] to say where the form submits to:

<form action="/form-result" up-validate up-validate-action="/form-render">

@marc-mabe
Copy link
Author

Hi @triskweline,

For naming I would argue pro up-validate-url as this is explicitly not about the form action but about an endpoint that validates/renders the form even if technically the form gets submitted.

How should it behave if only up-validate-url is defined without up-validate?
-> Should up-validate be implicitly enabled?

How should the behavior be on nested up-validate-url?

@triskweline
Copy link
Contributor

-> Should up-validate be implicitly enabled?

No. It's a modifying attribute of [up-validate].

How should the behavior be on nested up-validate-url?

We cannot easily allow nesting [up-validate-url] as Unpoly 3 batches multiple validations into a single request and guarantees only a single concurrent validation request per form.

See these slides:
http://triskweline.de/unpoly3-slides/#33
http://triskweline.de/unpoly3-slides/#34

If we allowed multiple [up-validate-url] within the same form this gets really complicated really fast.

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