Add data from a repeat into an array

Ah yes, i see the issue. You can do this a in a bit hacky way, changing:

{{myarr + query_related_filters.join(',', 'fts_filter_prop_fgn')}}

to

{{myarr + query_related_filters.join(',', 'fts_filter_prop_fgn') + ','}}

This way there will always be an , at the end, but i believe it should be working fine even with it.

Yeah nice, it is just that it leaves an empty ‘,’ at the end but this does not really bother since all the values are in the array. The issue now is how to make these values considered as numbers so the checkboxes are actually updated.

Are the values in your database stored as numbers actually?

Yes they are…

Just checked the Network tab. The ‘result’ array is like this
result":[“1”,“10”,“12”,“4”,“7”,“12”,""]}

I will try to use a flow and change the values to integer with javascript. Thank you!

Ok so some more changes will be required.
Please remove the split from the results setvalue step so it becomes just {{myarr}}
Then on the page, where you use the values use this code:

{{serverconnect1.data.result.split(',').map('$value.toNumber()')}}

@Teodor I am very close to achieving the final result. With the array we are great. The issue now is that I want to disable the checkboxes that do not contain any value of the array. But when the page loads the array will be NULL and this results to all checkboxes to be unchecked.

WHAT I WANT
I need to initially all checkboxes to be active. And when clicking to any of the checkboxes to load some relevant values which will deactivate some of the checkboxes (this functionality is already done), so my issue is how to write the condional right. I am trying something like the below

<li dmx-repeat:repeat2="query_related_filters">
    <input type="checkbox" name="input1" dmx-bind:value="fts_filter_prop_fgn" dmx-bind:disabled="!arrRel.items.contains(fts_filter_prop_fgn) && arrRel.items.hasItems()" dmx-on:change="arrRel.items.contains(fts_filter_prop_fgn) ? arrRel.remove(fts_filter_prop_fgn) : arr1.addUniq(fts_filter_prop_fgn)">{{fts_filter_prop_fgn}}
</li>

which means that if the value does not exist in the array and the array has some items the disable. But this for some reason disables all the checkboxes.

Thank you!!

Try something like:

dmx-bind:disabled="arrRel.items.hasItems() ? !arrRel.items.contains(fts_filter_prop_fgn) : false"

It does the same

I don’t see this on your page?

Try this page

So what should happen on this page exactly? How to test it?

Well if you click the Derma you will see that a
get_all_filters_that_exist_with_main_filter.php?filter_clicked=12
is loaded.
This returns the ‘result’ variable that we created.
The values of this array tell which checkboxes should not be disabled.
At the left of each filter (white, red etc) there is a number. This is the value that should match to the array in order to not be diabled.

Thanks!

So where are these checkboxes? Where to look at on your page?

Click the Color, Size,Type tabs and the will appear

Probably some value is wrong in your expression. Please double check the properteis/bindings names used.

dmx-bind:disabled="arrRel.items.hasItems() ? !arrRel.items.contains(fts_filter_prop_fgn) : false"

Your page is a bit complicated and uses quite a lot of repeats etc so it’s hard to navigate fast through your code…
Better test this on really simple page with just the checkboxes, array and the server connect on it.

Cool Teodor. I will check it out. Thank you for your time. If not working I will replicate it in a simplier example so its easier for you to help even more than you already did!

May the God of Mythos, Alpha, Fix be with you!

1 Like

@Teodor it is almost working. It disables the right values I only need to refine the flow which selects the main value to filter the rest of the checkboxes. Thank you very much!!!

1 Like

Is it still a best approach of adding items from Database query output to an array?