HTML5 Data Bindings Support Product Page

Answered

binding checkbox

Asked 09 Sep 2014 07:23:56
4
have this question
09 Sep 2014 07:23:56 Steven Irwin posted:
Hi,
I have a database with a field that is set to a 1 (TinyInt) if the field is true and 0 if not true. With other development environments I can bind this field to a checkbox and tell it which state represents checked and not checked.
I can't seem to do this with this extension. It is also unclear which of the many options you should bind for each input type (selects are another difficult one).
I want to have the checkbox show as checked when the database field is a 1 and as unchecked when a 0. I also want to be able to check the box and update the database with a 1 in that case when the form is submitted.
Can you please provide the correct way to bind the checkbox so that that the above works? In the past I have ended up using selects which are also difficult to achieve the above instead of a checkbox.
It would be good to have a guide to using html data bindings as well as the examples. The guide would specify when you use the different options eg. for a checkbox all the following are in the bind to list: input.value, input.alt, input.name, input.data.src, input.src, input.size, input.width, input.height, input.data.checked, input.id, input.class, input.title, input.data.show, input.data.hide
Thanks as always.
Steve

Replies

Replied 09 Sep 2014 09:18:11
09 Sep 2014 09:18:11 Teodor Kuduschiev replied:
Hi Steve,
Indeed, we've not created a tutorial about the checkboxes, soon we are going to update the Data bindings tutorials so this one will be added.
Meanwhile - what you can do is:
1. Click your checkbox
2. Click the data binding that you want to check if it is 0 or 1
3. Select the input.data.checked and click Bind
4. With the checkbox still selected click the HTML5 Data Bindings Formatter
5. In the format Field enter == 1 and click the Ok button.


That's all.
Replied 09 Sep 2014 09:39:54
09 Sep 2014 09:39:54 Steven Irwin replied:
Thanks Teodor,
That worked thank you.
Now I would like to be able to change the checkbox state and update the table with the new value. I can see that the Database Action Executor has the the checkbox on the form bound to the field and it looks like I have to do something with the formatter again?
Can you let me know - same thing - 1 for checked, 0 for unchecked.
Regards
Steve
Replied 09 Sep 2014 10:00:58
09 Sep 2014 10:00:58 Teodor Kuduschiev replied:
Well this should be as simple as adding a "1" as a value to the checkbox (using the DW Properties Inspector).
Then with the database updater you send this value as you do with the rest of the fields. When the checkbox is checked it returns the value of 1, if it isn't it does not
Replied 09 Sep 2014 10:53:53
09 Sep 2014 10:53:53 Steven Irwin replied:
Thanks Teodor.
I am guilty of over thinking this one ;-)
Excellent help as always!
Replied 04 Jan 2015 04:48:49
04 Jan 2015 04:48:49 Greta Garberini replied:
Got a similar thing but with "Y","N" as defined in MySQL SET instead of "1", "0"

<input name="active" type="checkbox" class="checkbox" id="active" value="Y" data-binding-checked="{{(clients.data[0].active == 'Y').( )}}">

This does not work. I guess the value must change?
I also need to update the state via $_POST in a second step.

update:
This works for me to show the state with Y/N:

<input name="active" type="checkbox" class="checkbox" id="active" data-binding-checked="{{(clients.data[0].active =='Y')}}">

Question remains how to update the state and write it into the database ...

Reply to this topic