Get value from table using repeater into each text input generated

Hi,
I’m trying to figure out to make this possible but I don’t know if is possible

Table in database has this columns:
-id
-id_est
-id_clase
-asis_1
-asis_2
-asis_3
-asis_4

Wappler structure is something like this:
-serverconnect1
-Form
–Div Repeater (4 times)
—Name
—Text Input (to get asis_1, 2, 3 using incremental number)

What I’m trying to do is to get into each Text Input generated by the repeater the value from respective column asis_1, asis_2, asis_3 and asis_4 from table in the database.

I not know how to do it, I’m trying this, but is not working:
dmx-bind:value="serverconnect1.data.buscar_registro_asistencia.asis_{{($index+1)}}"

Thanks.

The content inside bind value is already a dynamic expression, I don't thing adding another index expression will work.

Since you know its 4 items, it best to not use repeat and just bind it directly.

If you want to still use repeat, you could create a client side custom formatter that would fetch the correvt binding as per current index.

Sorry, can you please be more didactic with some kind of example, because I’m a graphic designer with not great skills in programming, and that’s the reason what I use this great software.

I’m using repeater because it’s generated from one input text all columns from database, instead of generated inside the repeater 6 text inputs for each columns.

This not works, beacause I need to use dynamic attibutes from a single text input to switch check if value is 1 or uncheck if null or 0.


The idea is to use this value from database to get switch check or uncheck using dynamic attributes, that’s why I use repeater with only one text input for each column except columns asis_1,2,3,4 that should be get dynamically,

If asis_db_1 is value 1 switch 1 is check if not uncheck
If asis_db_2 is value 1 switch 2 is check if not uncheck
etc, etc,.

Sorry if I can’t be more dicactic or specific with my problem.

I hope you can help me.

Thanks

I hope that I have understood what you want to do. In which case, have a look at the following

<div class="container mt-4">
    <div class="row">
        <div class="col">
            <h1>Available Dates</h1>
        </div>
    </div>
    <div class="row row-cols-3" is="dmx-repeat" id="repeat1" dmx-bind:repeat="5">
        <div class="col gy-4">
            <h6>Workday: {{$index + 1}}</h6>
            <div class="card">
                <div class="card-body">
                    <div class="form-check form-switch">
                        <input class="form-check-input" type="checkbox" value="" name="input1" dmx-bind:checked="(asis_1.value == 1) &amp;&amp; (asis_2.value == 1) &amp;&amp; (asis_3.value == 1) &amp;&amp; (asis_4.value == 1)">
                    </div>
                    <h5 class="card-title">Date</h5>
                    <input dmx-bind:id="'input_1_'+($index + 1)" name="asis_1" type="text" class="form-control" value="1">
                    <input dmx-bind:id="'input_2_'+($index + 1)" name="asis_2" type="text" class="form-control" value="1">
                    <input dmx-bind:id="'input_3_'+($index + 1)" name="asis_3" type="text" class="form-control" value="1">
                    <input dmx-bind:id="'input_4_'+($index + 1)" name="asis_4" type="text" class="form-control" value="1">
                    <input dmx-bind:id="'input_5_'+($index + 1)" name="asis_5" type="text" class="form-control">
                    <input dmx-bind:id="'input_6_'+($index + 1)" name="asis_6" type="text" class="form-control">
                </div>
            </div>
        </div>
    </div>
</div>

This is a generalised example which will need tweaking to suit.

1 Like

I think what Sid is telling you is this.
You get static and dynamic, if you want to get dynamic data you can do it like this

<!--The value property expects static data, so to make it dynamic you have to add {{...}} around the dynamic data you are getting.-->
value="{{dynamic-data}}"

<!--OR ALTERNATE WAY-->
<!--Add dmx-bind: in front of the value property and you can now input dynamic data without the {{...}} - as well as adding static data by enclosing it with 'static-words-go-here' - and if you want to join static and dynamic together you use + to do that.-->
dmx-bind:value="serverconnect1.data.buscar_registro_asistencia.asis+'_'+($index+1)"

Hope this helps explain it a bit, but I must be honest, if you are using Wappler as a graphic designer you can do all this directly in the UI and Wappler is clever enough to add all the correct code in itself so you do not need to even know all the strange stuff I explained. It would be safer to use it as Wappler generates it.

To do this in the GUI only try the following, maybe make a new page for testing by the way.

I assume you already have a database connection in Globals and I assume you want this form to update the asis_1, asis_2 database entries when a user slides them on or off.
If that is the case then.

  1. Go to the Workflows area, Server Actions,

  2. Create a new API action called whatever you want, like update_my_form inside the Steps add Database Multi Update, Open Update Options, select your database table, don't alter anything, click OK, save action.

  3. Create another new API action called whatever you want, like my_form_existing_data inside the steps add a Database Query, open Query Builder, add the same table you used in the last step, don't alter anything, click OK, save action.

  4. Now open your existing page, or a new one to test this out, right click App > Data > Server Connect, click action and choose your action called my_existing_form_data click Select.

  5. Right click Server Connect, make sure insert after arrow is selected, then select Generators > Bootstrap 5 Form Generator.

  6. In the popup window, first click Multi Record ON before you do anything else, then Click Select for your Server Action, this is the update_my_form one we made, click select, then click the Populate area, select the server action already on your page, probably called serverconnect1.data.query if you left all the naming as default. Clik Select.

The popup window populates you whole form, you just need to make some minor improvements, DO NOT change the Name fields, or Value fields, you can make your Label fields whatever you like, and the type fields must change.
First one is id, change type to hidden, and then choose all the other types as you need, you will notice there is no swipe as you have in your screenshots, just choose checkbox for now as that is the closest to a swipe in code, so you can change it later.

Make sure in last position there is a submit button, with type set to Submit, with no Value and no Name, so just a label and type, then hit OK.

A form should now magically appear on your page, mostly complete to what you need, and give you about the best base to start with, and fully valid code. Save your page, deploy or publish everything and go test.

When the browser page opens your form should already all be dynamically completed, you should be able to change anything you like and hit submit, and it should update all your changes to your database.

Whew, hope that helps.

1 Like

Sorry Ben, I was so busy typing, i did not see you answering already, haha, well now there are 2 options at least.

1 Like

No worries Paul, it looks like your explanation is far superior to mine. Expected no less from you :+1:

hahaha, thanks Ben, I always start off with the intention of giving a little sentence, and before i know it, it’s a book. My kids call me Mr Long Winded

Thanks you so much for taking your time, this part actually I'm tried before, the output is "_1" as you can see:

It's like before the plus sign it not get to concatenated (sorry if not the correct term) with after the plus sign and only output the index value. Because this doesn't exist: serverconnect1.data.buscar_registro_asistencia.asisor this serverconnect1.data.buscar_registro_asistencia.asis_.

What exists in table on database is: asis_1, asis_2, asis_3, etc,. each one is a column.

You can see it in this API action that I have:

So, that's why I need to call dynamically with a incremental number from a single text input using repeater.
This exist in server connect

serverconnect4.data.buscar_registro_asistencia.asis_1
serverconnect4.data.buscar_registro_asistencia.asis_2
serverconnect4.data.buscar_registro_asistencia.asis_3, etc, etc

The + just not working in this cases.

All this in fact I learned from your video: https://www.youtube.com/watch?v=QEoYxYtDKi0
This is gold for everyone that we starting using wappler. Thanks you so much for that. It's the structure that I already using for this little project.

Temporaly what I did was to remove the repeater and create each Switch inside a row and column, this is more tedius and insecure because now I have to hide dynamically the switch that is not using, no all options will be always visible, and insecure because they still are in code, any one with developer tool from browser can change values


Using repeter this not occurr, they are out of code and only show up dynamically with the propper action trigger.

Thanks Ben for your help, I'm not sure if this is the best option for me, because in that way all input from 1 to 6 will be generated in each instance of repeater. if repeater generated 5 times that's means tha in code will be 30 inputs. In my case I need to put in every input the value from the table form database and I think that do it 30 times for each query is too much.

I don't know, your are the experts, correct me if I wrong please. The system is thinking to using at least 4000 persons per month, in just one day will be 2000 persons registering attendance and in other day the other 2000 more.

I really appreciate your help, that's the reason what I love using wappler, your great support.

ahh ok, i think I understand what you are trying to do now.
serverconnect4.data.buscar_registro_asistencia[0]+'.asis_'+$number
Is the right sort of code, but is not really going to work how you think.

To be honest though it does not sound like a good structure, from a database perspective I mean, so what I would like to know is will there always be asis_1, 2, 3, 4, 5, 6 only or will there sometimes only be 3 or maybe 8 or them.

Maybe if I try explain the binding structure.
serverconnect4 - Is the name given when you bind the server action to your page

data - Is all the data inside it, so 1 database query or 20

buscar_registro_asistencia - Is the database query you are referencing, which is a Multi record query, so it is stored as an array of data which is why the data picker is adding [0] after it, this means only get the first record.

asis_1 - Is the column of data in your table you are trying to read.

Therefore this serverconnect4.data.buscar_registro_asistencia[0].asis_1 will return only one value from the first row in your database table and only from column named asis_1

The correct way to do this is to put it inside a repeat and only access the columns from your database you want, unfortunately because your database structure is strange even this is not great.

<div id="repeat1" is="dmx-repeat" dmx-repeat:repeat1="serverconnect4.data.buscar_registro_asistencia">
    {{asis_1}}{{asis_2}}{{asis_3}}{{asis_4}}{{asis_5}}{{asis_6}}
</div>

This would be my honest suggestion, your current table in your database looks like this

id cliente_id id_evento asis_1 asis_2 asis_3 asis_4 asis_5 asis_6
92 205 1384 true true false true false false

But you are trying to repeat the asis_1 - 6 part like they are in rows, which they aren’t so if asis_? is relative to id, cliente_id, id_evento then this database structure is going to cause you some headaches, by suggestion would be to create another table and move all the asis_? data into that.
So your database would look more like this

id cliente_id id_evento
92 205 1384
id foreign_key_sun_asis_taller_id asis
5 92 true
6 92 true
7 92 false
8 92 true
9 92 false
10 92 false

If you do this you will be able to repeat all asis columns on a per record basis from the first table.

Hi, sorry for late response I'm was taking my time in solve this.

Paul, i'm was using your recomendation, in fact, I'm was trying with two ways, just for learning and I would like to know wich one is more efective and less headaches.
My first way is this and it works.
Table (asis_taller):
image

This is a simple select that populate a hidden text input with the value of "id_evento" that I need to linking to the propper user and event id.

To make this works I had to create a form for each "asis" column from 1 to 6, in this case are 6 forms for each "asis" column with a simple server action to insert for first time or update if "cliente_id" and "id_evento" exists, in this way only the propper column is filled with Dynamic action using value change to submit if Switch change:
App Structure


API's

Second way works, but....
Table 1:
image
Table 2:
image

This second way looks like first one.

The differences is how this is generated using repeater, the number of repeats depends with the value of the select option, and again each repeater with a form. If Switch change the dynamic event trigger to submit these unique form.
image

Now in API's two inserts for each table:

It works, and here is the "but...", with the second way each Switch that trigger the submit save one record (see table 2) but if for example the user not register first attendance and if is out of date it get locked by the condition, this automatically deactivate that Switch, now second switch is available for new date attendance, if user toggle on the Switch this save new record (table 2), but like this is actually the first record, it's impossible to define it to the right Date, so, this last record belongs at firts attendeance and not the second attendeance like should expect.
I'm thinking in a new column inside "asis" table, a new index for event.

But What I really want to know is if you can help me is telling me wich one is better, less headaches.
Sorry the long question.

So sorry, but I am pretty confused.

Maybe try explain the end result of what you would like

Are the following values linked like this
2021-09-11_07-45-54

image
When toggle is on it store “1”. If date is too much ago or If date is not on date no record is save, it’s null.
Only when toggle is on store “1”
Each toggle is linking with one column “asis_1”, etc,.
The “select option” is for save the correct “id_evento” in table and generate number of repeats, this “select option” is populating dynamically from this two tables, this allow to generated the propper repeats for each event.
image
image

I am just trying to find a gap in my work load and will try send you some idea what to try.