Dynamic Checkbox's from a dynamic list - how to display

Hi,

I have a dynamic list of resources clients can choose from on an insert form called Service, they are displayed as checkboxes in this case. The list is generated from a resource table.

The Service page inserts date into a service table but inserts the resources selected into a resource-used table. This table used the service table ID as the join.

I have create a test page to show the selected resources-used items, again using checkboxes. I followed a post by Teodor on How to create Dynamic Checkboxes.

In the image below you can see the results for a test service record. The top list in a straight forward repeat of all resources available, the lower list shows the resources selected during the insert stage of the service record.

The lower list uses the following code:

    <div class="container">
    <div id="repeatselectedresources" is="dmx-repeat" dmx-bind:repeat="scservice.data.query">
        <div class="form-check form-switch">
            <input class="form-check-input" type="checkbox" name="checkboxes[]" dmx-bind:id="'checkbox'+res_id" dmx-bind:value="res_id" dmx-bind:checked="srv_online_book">
            <label class="form-check-label" dmx-bind:for="'checkbox'+res_id"> - {{res_name}}</label>
        </div>
    </div>
</div>

The repeat scservice.data.query is a database query consisting of;

service table, joined to the resources-used table by the service-id and the resources table joined by the resource-id in order to get the resource name. (I can show this in more detail is nessary)

My question is;

How do I get the resources-used list to also include the resources not selected so that a client can later select them?

Hope this makes some sense

Many thanks
CK

I think I understand.
How many tables do you have?

Hi Franse

There are three tables;

services
resources
resources-used

Query looks likes this:

SELECT
'resources-used`.ru_id,
`resources-used`.res_id,
 resources.res_name,
 services.*
FROM services
LEFT OUTER JOIN `resources-used`
ON services.srv_id = `resources-used`.srv_id
INNER JOIN resources
ON `resources-used`.res_id = resources.res_id
WHERE services.srv_id = ?

Do you mean you actually want to display ALL of the possible resources stored in the resources table ONLY that each of them will display on this page with an associated checkbox that shows either a Checked status or, if unselected, the open un-checked checkbox?

So that the user still sees ALL available resources from that resources table.

As in your example the lists will be sorted, perhaps sequentially showing Checked Resources then Unchecked Resources that can still be added – clicked on. So that the User is actually eligible to EDIT their previous form session.

So that the Un-checked values can still be checked, too, or even if the User wants to De-select a checked value as needed before RE-Save/Submit of the form ?

Yes, that’s exactly what I’m trying to achieve but I can’t figure out how to show the unselected resources using the query above, I somehow need to include them in the result.

I did that some time ago on an admin panel of an accommodation site. It was quite a complex process if I recall but I probably have the code archived, will check when back in office.

1 Like

I have a code too. Don’t remember exactly
I will check it out later.
Something like having another query where the condition is query2.id = query1.id.
On the ac, the repeats expression is binded to query2.
The checked status == 1.
Something like that.
I’ll have the computer in about 8 hours since I’m work.

1 Like

Thanks Brian, that would great to look at.

Do it this way it works

<div class="col-12">
                            <div class="form-group md-3"> <label for="input3" class="form-label"><b class=" text-primary">SELECIONE OS DIFERENCIAIS</b><br></label>
                                <div is="dmx-checkbox-group" id="group_diferenciais" class="checkbox-group">
                                    <div class="row">
                                        <div class="form-check-group col-12 col-lg-6 col-xl-4" dmx-repeat:rep_diferenciais="api_sel_diferenciais.data.query">
                                            <label class="form-check-label" dmx-bind:for="d{{id}}"><input class="form-check-input" type="checkbox" name="mdiferenciais" dmx-bind:id="d{{id}}" dmx-bind:value="id" dmx-bind:checked="get_anuncio_by_token.data.query.diferenciais.values(`anuncio_diferenciai_id`).contains(id)"> <b>{{nome}}</b></label>
                                        </div>
                                    </div>
                                </div>
                                <input type="hidden" name="diferenciais" dmx-bind:value="group_diferenciais.value" id="inp_diferenciais">
                            </div>
                        </div>

Thanks Franse, look forward to seeing what you have.

I must repeat “I think I understand” as I’m from a country where english is not the current language :frowning:
So:

This can work? I changed the names for a better reading, in my case “services” are like “options” or “amenities”

DATABASE

  1. Table of appointments
    image

  2. Table of services
    image

  3. Data (related is the appointment id, and service_id, well…)
    image

SERVER SIDE

image

  1. Query of Appointment where appointment.id = {{$_GET.id}}
  2. Query of Service
  3. Query of Data where “related” is = appointment.id and a join (with “services” table) where id_service (from table services) = dataservices.service_id (from table dataservices)

CLIENT SIDE

image

  1. Query where I create my id parameter
  2. Server connect where I have linked $_GET.id to my query.id
  3. The “Repeat step” is from the serverconnect1.queryData
  4. The checkbox is “checked” as the value (in dynamic atribute) has the condition “field == 1”)

So:
image
image

I hope this is what you’re talking about, otherwise I’ll be very embarassed and I’ll take english lesson asap.

1 Like

Thank you Franse,

I will give the above a go and report back…