checkbox[Permalink]The checkbox widgetIn the fields.ini file you can specify a field to be edited using a checkbox widget by setting widget:type to checkbox. A checkbox widget can function in 2 different ways depending on the parameters that you assign to the field. Example 1: A TinyInt (boolean) fieldSuppose our table has a tinyint field named "Active" which specifies whether the record is currently in use. This field will store a value of either 0 or 1. So we configure this field in our fields.ini? file to use a checkbox widget as follows:
Results: Example 2: A repeating field (multiple checkboxes for one fieldCheckboxes can store multiple values in a single field by setting the vocabulary? directive and applying it to a varchar or text field. In this case there will be one value saved per line. In this example, suppose we have a varchar field named categories which uses the categories valuelist? to specify the different categories that can be checked at any given time. Our valuelists.ini file might look like:
And our fields.ini file looks like:
Now if we save a record with categories 1, 3, and 5 checked, then the categories column of our row in the database will store something like:
i.e. one category id per line. Note that using this method, your database will not be normalized because you are storing multiple values in a single field. However in many applications this is sufficient.
Results: Example 3: Using a "Categories" relationship"""(Note: This example requires Xataface version 1.2 or higher)""" Example 2 above shows how we can easily add and remove a record from multiple categories using checkboxes. However it required multiple pieces of information to be stored in a single database field which may or may not be advantageous for your database design. If you're looking for a more normalized database schema you would probably design your database as follows for this case:
With out table structure we will first want to define a relationship from Books to Categories to reflect the connection between books and categories. The relationships.ini file for this might look like:
And our fields.ini file for the Books table might look like:
Results: Related Parameters
|