Check boxes vs radio buttons or data insert and update


#1

I’m finding it hard to do this consistently. I have one checkbox which works to store the data in the database using the value of the static value parameter and another one which doesn’t and the code is virtually the same except for the static value. They are not groups. I’m using it basically as a value or no value field. What’s the recommended way to do this so that the checkbox value is retireved and checks or unchecks accordingly.

Thanks,
Rick


#2

Hello @marsalstudios
What exactly the issue is - you cannot insert a value in the database, or you cannot display a database value in a checkbox (i.e. checked/not checked)?


#3

I can put the static value in the database from the checkbox when it is checked, no problem. I’m having trouble getting the value back to display the checkbox as checked/notchecked when retrieving the record in a query.

Thanks,
Rick


#4

Could you just not bind ‘checked’ to the checkbox input, like below? If your database field named ‘red’ for instance is not empty the checkbox is checked:

<input type="checkbox" value="red" dmx-bind:checked="red != ''">

I have zero idea if that is a correct Wappler workflow but it seems to work for me.

For instance if you’re using ‘dmx-data-detail’ to retrieve the details based on passing an ‘identifier’ from a link it would look something like below. IF the database field associated with the checkbox for ‘oranges’ as the value is NOT empty then it must have a value of ‘oranges’ as previously selected and as it’s NOT empty then the checkbox is ‘currently’ selected.

<a href="#" dmx-on:click="fruit_details.select(productCode)">{{ name }}</a> 


<dmx-data-detail id="fruit_details" dmx-bind:data="conn_fruits.data.fruits" key="productCode">
<h6>{{ data.productCode }}</h6>
<h3>{{ data.name }}</h3>
<input type="checkbox" value="oranges" dmx-bind:checked="data.oranges != ''"> 

</dmx-data-detail>

This workflow assumes that you’re requesting the ‘details’ to be retrieved and shown on the same page as where your links to the details are listed.


#5

Use dynamic attributes -> checked -> select your dynamic binding (coming from the database) and add your condition there, like: someexpression == 1

the checkbox will be checked if the dynamic expression equals 1 and if it’s not 1 it won’t be checked.


#6

thanks , that worked great!!!