<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.7.2" -->
<rss version="2.0">
    <channel>
        <title>checkbox[ Search for &quot;&quot;]</title>
        <description></description>
        <link>http://xataface.com/wiki/index.php?-action=single_record_search&amp;-table=wiki&amp;page_id=%3D69&amp;-cursor=0&amp;-skip=0&amp;-limit=30&amp;-mode=list&amp;--subsearch=</link>
        <lastBuildDate>Thu, 23 May 2013 00:58:47 +0100</lastBuildDate>
        <generator>FeedCreator 1.7.2</generator>
        <item>
            <title>checkbox</title>
            <link>http://www.xataface.com/wiki/checkbox</link>
            <description>&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Field&lt;/th&gt;&lt;th&gt;Value&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page name&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;checkbox&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page id&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;69&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page title&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;checkbox&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Content&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;
&lt;h2 id=&quot;toc0&quot;&gt;The checkbox widget&lt;/h2&gt;
&lt;p&gt;In the &lt;a href=&quot;/wiki/fields.ini_file&quot;&gt;fields.ini file&lt;/a&gt; you can specify a field to be edited using a checkbox widget by setting &lt;a href=&quot;/wiki/widget%3Atype&quot;&gt;widget:type&lt;/a&gt; to &lt;a href=&quot;/wiki/checkbox&quot;&gt;checkbox&lt;/a&gt;.  A checkbox widget can function in 2 different ways depending on the parameters that you assign to the field.&lt;/p&gt;

&lt;table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;&lt;tr&gt;&lt;td&gt;
&lt;div id=&quot;toc&quot;&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;
	&lt;div style=&quot;margin-left: 0em;&quot;&gt;&lt;a href=&quot;#toc0&quot;&gt;The checkbox widget&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc1&quot;&gt;Example 1: A TinyInt (boolean) field&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc2&quot;&gt;Example 2: A repeating field (multiple checkboxes for one field&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc3&quot;&gt;Example 3: Using a &amp;quot;Categories&amp;quot; relationship&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 0em;&quot;&gt;&lt;a href=&quot;#toc4&quot;&gt;Related Parameters&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;


&lt;h3 id=&quot;toc1&quot;&gt;Example 1: A TinyInt (boolean) field&lt;/h3&gt;
&lt;p&gt;Suppose our table has a tinyint field named &amp;quot;Active&amp;quot; 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&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=fields.ini&quot;&gt;?&lt;/a&gt; file to use a checkbox widget as follows:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;[Active]
  widget:type=checkbox&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Results:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://media.weblite.ca/files/photos/Picture%2024.png?max_width=640&quot; alt=&quot;http://media.weblite.ca/files/photos/Picture%2024.png?max_width=640&quot; width=&quot;110&quot; height=&quot;42&quot; /&gt;&lt;/p&gt;


&lt;h3 id=&quot;toc2&quot;&gt;Example 2: A repeating field (multiple checkboxes for one field&lt;/h3&gt;
&lt;p&gt;Checkboxes can store multiple values in a single field by setting the vocabulary&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=vocabulary&quot;&gt;?&lt;/a&gt; directive and applying it to a varchar or text field.  In this case there will be one value saved per line.&lt;/p&gt;

&lt;p&gt;In this example, suppose we have a varchar field named &lt;strong&gt;categories&lt;/strong&gt; which uses the &lt;strong&gt;categories&lt;/strong&gt; valuelist&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=valuelist&quot;&gt;?&lt;/a&gt; to specify the different categories that can be checked at any given time.  Our &lt;a href=&quot;/wiki/valuelists.ini_file&quot;&gt;valuelists.ini file&lt;/a&gt; might look like: 
&lt;pre&gt;&lt;code&gt;[categories]
    __sql__ = &amp;quot;select id,name from categories&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;/p&gt;

&lt;p&gt;And our &lt;a href=&quot;/wiki/fields.ini_file&quot;&gt;fields.ini file&lt;/a&gt; looks like: 
&lt;pre&gt;&lt;code&gt;[categories]
    widget:type=checkbox
    vocabulary=categories&lt;/code&gt;&lt;/pre&gt;

 &lt;ul&gt;
    &lt;li&gt; Note that you don't need to name the field the same as the valuelist.  It just worked out this way.&lt;/li&gt;
&lt;/ul&gt;

&lt;/p&gt;

&lt;p&gt;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: 
&lt;pre&gt;&lt;code&gt;1
3
5&lt;/code&gt;&lt;/pre&gt;

 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.&lt;/p&gt;

&lt;p&gt;Results:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://media.weblite.ca/files/photos/Picture%2025.png?max_width=640&quot; alt=&quot;http://media.weblite.ca/files/photos/Picture%2025.png?max_width=640&quot; width=&quot;629&quot; height=&quot;33&quot; /&gt;&lt;/p&gt;


&lt;h3 id=&quot;toc3&quot;&gt;Example 3: Using a &amp;quot;Categories&amp;quot; relationship&lt;/h3&gt;
&lt;p&gt;&amp;quot;&amp;quot;&amp;quot;(Note: This example requires Xataface version 1.2 or higher)&amp;quot;&amp;quot;&amp;quot;&lt;/p&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt; Books table - Stores all of the books.&lt;/li&gt;
    &lt;li&gt; Categories table - Stores all of the categories&lt;/li&gt;
    &lt;li&gt; Book_Categories table - Stores mapping of books to categories.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;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 &lt;a href=&quot;/wiki/relationships.ini_file&quot;&gt;relationships.ini file&lt;/a&gt; for this might look like:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;[categories]
    Books.Book_ID=&amp;quot;$Book_ID&amp;quot;
    Book_Categories.Category_ID=Categories.Category_ID&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And our &lt;a href=&quot;/wiki/fields.ini_file&quot;&gt;fields.ini file&lt;/a&gt; for the Books table might look like: 
&lt;pre&gt;&lt;code&gt;[categories]
    widget:type=checkbox
    transient=1
    relationship=categories&lt;/code&gt;&lt;/pre&gt;

 &lt;ul&gt;
    &lt;li&gt; Note that there is no need for our field to be named the same as our relationship.  It just turned out this way.  Also note that we used the transient=1 flag here because the Books table no longer has a categories field in the database.  This field is defined purely for the benefit of the edit form so that we will get a checkbox group to select the book's categories.&lt;/li&gt;
&lt;/ul&gt;

&lt;/p&gt;

&lt;p&gt;Results: &lt;img src=&quot;http://media.weblite.ca/files/photos/Picture%2025.png?max_width=640&quot; alt=&quot;http://media.weblite.ca/files/photos/Picture%2025.png?max_width=640&quot; width=&quot;629&quot; height=&quot;33&quot; /&gt;&lt;/p&gt;


&lt;h2 id=&quot;toc4&quot;&gt;Related Parameters&lt;/h2&gt;
&lt;ol&gt;
    &lt;li&gt; vocabulary&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=vocabulary&quot;&gt;?&lt;/a&gt; - Assigns a valuelist to be used as the options for this checkbox group.&lt;/li&gt;
    &lt;li&gt; repeat&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=repeat&quot;&gt;?&lt;/a&gt; - A boolean value indicating whether this field should be treated as a 'repeating field'.  A repeating field is one with multiple checkboxes.  By default the checkbox widget operates as a single checkbox that controls a boolean value.&lt;/li&gt;
    &lt;li&gt; &lt;a href=&quot;/wiki/relationship&quot;&gt;relationship&lt;/a&gt; - (Only applicable to transient&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=transient&quot;&gt;?&lt;/a&gt; fields).  If the &lt;a href=&quot;/wiki/relationship&quot;&gt;relationship&lt;/a&gt; directive is set then this field can be used to add/remove records from a relationship.&lt;/li&gt;
&lt;/ol&gt;

&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Language&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;en&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;</description>
            <author>checkbox</author>
        </item>
    </channel>
</rss>
