Best practice Dynamic Checkbox arrays per DB row or seperate DB rows?

I’m using dynamic Checkboxes, hopeful I did it right:

<div class="col col-xl">
                  <div class="form-group" id="input1_group" is="dmx-checkbox-group">
                    <legend class="col-sm-2 col-form-label">Some checkboxes</legend>
                    <div class="row" is="dmx-repeat" id="repeat1">
                      <div class="form-check">
                        <input class="form-check-input" type="checkbox" id="input1_1" is="dmx-checkbox" value="" name="1">
                        Architektur / Planung&nbsp;</div>
                      <div class="form-check">
                        <input class="form-check-input" type="checkbox" id="input1_1" is="dmx-checkbox" value="" name="2">
                        Autolackierer&nbsp;</div></div>
                  </div>
                </div>

The Gui Looks like (maybe I got an error with Naming for all fields) :slight_smile:

image

Now I as @Teodor his Post with storing these Checkboxes as Arrays for his Meal Example. But I have a helptable in MySQL where I wanna insert these infos as separate MySQL rowinsert. So per Checkbox, one mysql insert.

But now my question: What makes more sense? I mean I need to add later also DELETE Actions and UPDATE Actions. Whats more robust and easier to handle?

If I go with separate DB Row Inserts, how to handle that? Any example?

Bonus Question: How to limit the Checkable forms to 5 ? SO If I would have 10 Checkboxes, only 5 of them are Checkable :smiley:

Hi Freddy,
In order to store the checkboxes as new rows you need to:

  1. All of our checkbox names must be the same, followed by [] For example: name="mycheckbox[]" and add different values to them:

Screenshot_8

2, Import the form under globals, the checkboxes will appear as an array multiple in POST vars:

Screenshot_9

  1. Add repeat step, and repeat the POST var created by your checkboxes:

  1. Add the insert step there, inside the repeat, and as vallue select $value returned by your repeat:

When you submit your form, a new record will be created for each checkbox selected.

3 Likes

BONUS ANSWER

Select ONE of the checkboxes which has the same name[] as the rest, add new validation rule and under collections select max items. Enter 5 or 10 or whatever value you need:

1 Like

@Teodor how smooth your solution is implementable in any of these wappler projects! It amazes me everytime and I‘m sure that post helps alot of users and grow up documentation, adoption and community ! :ok_hand:t5::grin:

Will try that solution out and come back! That [Array] modification is what I thought about it to pass it to my Insert Repeat statement! Great and that „Max“ selectable checkbox solution, is even more simple as I thought… My god! I lost such alot of time with playing around with all these standalone coding frameworks out there…

@Teodor one question by side: When would you go for solution A or B?

A is like your post about Meal Menus separated via split/join for each single row.

B solution which I’ll take now : Maybe I have more flexibility later for doing stats, queries, reports and store each checkbox values into separate rows as written in my question.

… hopefully Update statement is similar I guess for solution B… :laughing:

2 Likes

I prefer using a details table (like your solution B) related to the main table with a primary key.
The tutorial you mention just shows what most of the users here are doing - store everything in one table :slight_smile:

1 Like

@Teodor works like a charm! Amazing! UsedI the dmx bind for the values. Wooow so cool!

BTW: I got ISO Date like 31.12.2018 and Validation says Error… is it possible to change that check to ISO? Looks like my feld is DD.MM.YYYY but JS validation does US Date stuff… ?

Or maybe there is a trick to just change that js library to Europe standard. Cause its still “English” and Week starts not with “Monday” … :sleepy:

Hi @Teodor,

I am trying to store the multiple checkbox values that I receive as an arrya, in a single column as a comma-separated-value.
But the join does not seem to function without a column name. Any suggestions on how I can convert the array to a csv?

Not sure what you mean by this?

Join function on client side just needs a character parameter.
But, join function on server sides asks for a character and a column name.
Without column name, I get this error:

$_POST.OptionValue.join(',', '') OR $_POST.OptionValue.join(',', ' ')
image

Is there a way to convert my input OptionValue which has a value like ["4","5"] to a CSV like 4,5 so that I can store it in table column?

What server model are you using?

NodeJS

Please replace your \lib\formatters\collections.js with this new version:

collections.zip (1.1 KB)

it will fix the issue.

1 Like

Works! Thanks. :slight_smile:

(I wasn’t getting notifications for this post since it was in “Tracking” mode. Hence the late replies.)