How to get current URL and url param and add onto it

Hi,

I have a browser goto set to go to a url and a url parameter. The page already has a url parameter and I want to add to the url this new param (‘av’).

I tied GET but can’t get it to work.

<input class="form-check-input" type="checkbox" id="input_toggle_av" name="input_toggle_av" value="av=1" dmx-bind:checked="(query.av == 1)" dmx-on:changed="checked ? browser1.goto('NEEDS-TO-BE-EXISTING-URL-AND-PARAMETER?av=1') : browser1.goto('EXISTING-URL-AND-PARAMETER')">

Hello,
First you need define your url parameters. This happens in App Structure - select App and click the Define Query Params button.
Then your query params will be available in the data picker for selection.

Thanks @Teodor! Of course, should have thought of that. :slight_smile:

1 Like

@Teodor, ss there a way to not display the param if it is empty, e.g. “av=”? Just to have clean urls being displayed.

What do you mean? To display it where?

Not to display an empty param in the URL when using Browser goto action. I have three parameters, and if they are empty I don’t want them to display in the go to URL. For example in ‘browser goto’ “something.php?param1=&param2=&param3=abc”, in this case param1 and param2 shouldn’t be displayed in the redirecting/goto URL.

In this case you will have to check if the parameter value exists and include it only then in the URL you want.

Is there a way I can do that? To check if a param value exists and only display the parameter if a value exists? Is there a way I can do this in the browser goto?

Where do your parameter values come from? How do you pass them to the goto event?

One of them comes from a search input field, the other is offset (pagination) and the other is based on a checkbox selection.

Can you please post your current code so i can check if/how can this be implemented there?

Here is a checkbox I am using to send to browser goto

    <form id="form_clean_toggle">
    <div class="form-check">

    <input class="form-check-input" type="checkbox" id="input_toggle_av" name="input_toggle_av" value="av=1" dmx-bind:checked="(query.av == 1)" dmx-on:changed="checked ? browser1.goto('search_results.php?media='+query.media+'&amp;offset='+query.offset+'&amp;av=1') : browser1.goto('search_results.php?media='+query.media+'&amp;offset='+query.offset+'')">

    <label class="form-check-label small text-success" for="input_toggle_av">Admin View</label>
    </div>
    </form>

So you have some static parts of the url that need to be added or removed there in this goto event. That would become a huge, complex and hard to maintain expression. I do not advise doing this.

In that case, I can drop using URL param for “av”. The whole idea is that if the user selects the Checkbox, it display extra elements/buttons on the page that would otherwise not be displayed. So if I drop using URL parameter values is there another way to display those elements? maybe if the Checkbox sets a global ‘session’? and I can display those elements based on session?

You can set a session yes. And on check you can set the session value, which will be passed to other pages.
What is the whole idea behind clicking a checkbox that redirects to another page? Are you sure that is a good ux idea? Checkboxes are not usually associated as navigation elements on the pages. They enable or disable / turn off or on some stuff.

I don’t necessarily want a redirect on checking the checkbox, but rather just show/hide several buttons on the page when the checkbox is checked - it just needs to hold its state through pagination. It’s on a list page.
So a session would be a better solution? If so, do I define a global session in the app? And then on checked (in dynamic event) I would select the session from dynamic picker and set an = value?

You can set a session value as explained here (doesn’t mind it shows multiple pages, the idea is the same):

But actually if you just want to show and hide elements on the page you can use the dynamic attributes show/hide and check whether the checkbox is checked or not.

1 Like

Thanks for the link, will check it out.
Actually your second point it a really good idea - I didn’t think about it in reverse, show/hide the elements if checkbox is checked/unchecked… I was thinking all this time in relation to the checkbox - if checkbox is checked/unchecked then show/hide elements.
I like it @Teodor - I will give it a try and see how I go with it. Thank you!

1 Like

@Teodor, thanks very much Teodor!! Your last suggestion about using dynamic attributes to check whether the checkbox is check or not worked beautifully!!! So much cleaner and no page reload and the selection is remembered from page to page :slight_smile: loving Wappler!!

1 Like