Macro render_xxx: How to capture an input before triggering data-href?

Hi Adrian,

In a section using macro render_ with class i-button and data-href=<final_url>, I would like on some condition to open first a dialogue with client to capture one information before action POST of <final_url>,
I see the way you do is to go through another form first to capture the input, which means that I will have to declare a form_url and a class to handle that form_url, and use it first as destination of data-href, and finally trigger my <final_url> from the new form…

I would like to avoid that heavy solution because I just want to capture a simple input from client (no need to go through server) before triggering the <final_url> linked to the button,
something like: onclick=f(), and in f(), check some condition, popup to get the input then post the data-href…

Is there a way to do that with the macro style ?

Thanks,

Your question is rather abstract so I’m not sure whether you use any of the declarative magic to send AJAX requests or use custom JS for it…

If it’s the former and all you need to do is show a confirmation prompt, maybe data-confirm helps (if you search for it in the code you should find a bunch of places where it’s being used).

I use the macro style to render a section, like the ones used in Settings of the event to render section dates, location …
macro declared with class

        <a class="i-button"
            data-method="POST"
            data-href="url"
            data-params='param'
            data-ajax-dialog>

And I would like to not POST directly the url in data-href on button click, but instead on click, do first some checks, and open a popup to get an input from user, before posting the final url.
data-confirm is just to confirm the action, here I need to gather an extra info before triggering the action.

I like the macro style and wonder if I can do that using that style…

the post remove some text…
I meant: macro in html using
data-method= POST, data-href, data-ajax-dialog.

You need to wrap code blocks in triple-backtick fences (standard markdown way of indicating a code block); I just edited your post to fix it.

Depending on what your goal is, maybe ajaxForm:validateBeforeSubmit or ajaxForm:beforeSubmit could be useful to you…

Which means: I add a javascript in the form, that’s clear.
I just wonder if there is a way to do it inside the macro, something like “data-confirm” …

Inline JS code you mean? No, that’s not supported.

Got it.
I would be nice to have later on something like:
data-confirm-with-input= (text of confirm, f1, f2…

and when used in the macro, it will popup the confirmation windows which contains the fields f1, f2 for user to input data,
then on confirmation, the POST will be done with f1, f2 … as parameters.
That would be great ! :slight_smile:

I think you should use the standard ajaxdialog with a WTForm on the server for this - I guess you need to handle data entered there on the server anyway?

Not exactly,
I don’t want to display the fields for input on the wtform containing the button action,
but only displaying the field to input when the button is clicked, then send that field as parameter to the POST.

The real context is:
on the registration page, when clicking on “Print badge”, I want to ask user to input the reason of printing (if the badge has already been printed) before going to the page configuration badge (url of data-href).