{"id":10481,"date":"2018-12-18T10:24:03","date_gmt":"2018-12-18T16:24:03","guid":{"rendered":"http:\/\/www.mrc-productivity.com\/techblog\/?p=10481"},"modified":"2023-12-06T14:03:25","modified_gmt":"2023-12-06T20:03:25","slug":"creating-toggle-switches-in-bootstrap-applications","status":"publish","type":"ht_kb","link":"https:\/\/www.mrc-productivity.com\/techblog\/?ht_kb=creating-toggle-switches-in-bootstrap-applications","title":{"rendered":"Creating Toggle Switches in Bootstrap applications"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Overview<\/h2>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\"><em>Click <a href=\"https:\/\/www.mrc-productivity.com\/docs\/knowledge-base\/new-form-input-options#toggle-switches\">here<\/a> to access current documentation for this feature.<\/em><\/p>\n\n\n\n<p>Bootstrap dictionaries support the use of Toggle Switches.&nbsp; To implement these, you must be using a Maintainer application. This post will walk you through how to add this to your maintainer form.<\/p>\n\n\n\n<p>A visual of a toggle switch can be seen <a rel=\"noreferrer noopener\" href=\"https:\/\/getbootstrap.com\/docs\/5.1\/forms\/checks-radios\/#switches\" data-type=\"URL\" data-id=\"https:\/\/getbootstrap.com\/docs\/5.1\/forms\/checks-radios\/#switches\" target=\"_blank\">here<\/a>. Toggle switches work for fields that have one of two possible values, such as &#8216;Yes&#8217; or &#8216;No&#8217;, &#8216;0&#8217; or &#8216;1&#8217;, &#8216;Male&#8217; and &#8216;Female&#8217;, etc.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<p>In the Field Settings tab of your maintenance application, find the field that you would like to create a toggle switch for. This should be a field that only accepts two values (Yes\/No, 0 or 1, Male or Female, etc.)<\/p>\n\n\n\n<p>In the validity relation (\u2018Validity Rel\u2019) column, select \u2018CB\u2019 for checkbox. In Validity Check Value, enter here the value you want to write to the database when the switch is toggled on.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"\/techblog\/images\/toggleswitch1.jpg\" alt=\"\" width=\"609\" height=\"332\"\/><\/figure>\n\n\n\n<p>Compile the application (if rebuilding an existing app, make sure to overwrite the HTML on the maintainer form). Open m-Painter and locate your field in your maintainer form page. There should be a checkbox here. Right-click on the row and use the &#8216;User Interface&#8217; -&gt; &#8216;Edit Element&#8217; tool to bring up the HTML source.&nbsp;<\/p>\n\n\n\n<p>&nbsp;By default, the checkbox and label will look like this:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;label&gt;\n&lt;input ${checked('active',row.active,'y')}=\"\" class=\"mrcinput\" ${disabled('active')}=\"\" id=\"ACTIVEY\" name=\"ACTIVE\" type=\"checkbox\" value=\"Y\" \/&gt; Y&lt;\/label&gt;<\/code><\/pre>\n\n\n\n<p>Change this to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;<strong>div class=\"toggleSwitch\"&gt;<\/strong><br>&lt;input ${checked('active',row.active,'y')}=\"\" class=\"mrcinput\" ${disabled('active')}=\"\" id=\"ACTIVEY\" name=\"ACTIVE\" type=\"checkbox\" value=\"Y\" \/&gt;<br><strong>&lt;label for=\"ACTIVEY\"&gt;&lt;\/label&gt;&lt;\/div&gt;<\/strong><\/code><\/pre>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\"> The value inside&nbsp;<code><em>&lt;label for=\"<strong>ACTIVEY<\/strong>\"&gt;<\/em><\/code> has to match the ID value in <code><em>id=\"<strong>ACTIVEY<\/strong>\"<\/em><\/code><\/p>\n\n\n\n<p>After pressing &#8216;OK&#8217; and saving your changes, you should visually see on the maintainer form at runtime the checkbox is now a toggle switch (If not, clear your browser cache completely and refresh the application)<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"\/techblog\/images\/toggleswitch3.jpg\" alt=\"\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Overview Bootstrap dictionaries support the use of Toggle Switches.&nbsp; To implement these, you must be using a Maintainer application. This post will walk you through how to add this to your maintainer form. A visual of a toggle switch can be seen here. Toggle switches work for fields that have&#8230;<\/p>\n","protected":false},"author":1,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[154],"ht-kb-tag":[],"class_list":["post-10481","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-bootstrap"],"_links":{"self":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb\/10481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10481"}],"version-history":[{"count":23,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb\/10481\/revisions"}],"predecessor-version":[{"id":12217,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=\/wp\/v2\/ht-kb\/10481\/revisions\/12217"}],"wp:attachment":[{"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10481"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fht-kb-category&post=10481"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/techblog\/index.php?rest_route=%2Fwp%2Fv2%2Fht-kb-tag&post=10481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}