<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.dabo.leafe.com/index.php?action=history&amp;feed=atom&amp;title=HowToCustomizeCheckboxes</id>
	<title>HowToCustomizeCheckboxes - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.dabo.leafe.com/index.php?action=history&amp;feed=atom&amp;title=HowToCustomizeCheckboxes"/>
	<link rel="alternate" type="text/html" href="https://wiki.dabo.leafe.com/index.php?title=HowToCustomizeCheckboxes&amp;action=history"/>
	<updated>2026-11-22T04:27:22Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://wiki.dabo.leafe.com/index.php?title=HowToCustomizeCheckboxes&amp;diff=4172&amp;oldid=prev</id>
		<title>Ed: Created page with &quot;How To Customize a Check Box  If you need a column that can assume only one of two mutually exclusive values, a way to manage it in the front end is to use a dCheckbox.  Nativ...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.dabo.leafe.com/index.php?title=HowToCustomizeCheckboxes&amp;diff=4172&amp;oldid=prev"/>
		<updated>2020-05-17T14:03:37Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;How To Customize a Check Box  If you need a column that can assume only one of two mutually exclusive values, a way to manage it in the front end is to use a dCheckbox.  Nativ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;How To Customize a Check Box&lt;br /&gt;
&lt;br /&gt;
If you need a column that can assume only one of two mutually exclusive values, a way to manage it in the front end is to use a dCheckbox.&lt;br /&gt;
&lt;br /&gt;
Natively dCheckbox binds to a boolean (true/false) column , but sometimes is useful to have two values for the field and may be another couple of values to display to the user, and both of them sometimes cannot be boolean. An example can clarify this situation (the database is postgres 8.1);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;&lt;br /&gt;
  CREATE TABLE t_preferences (&lt;br /&gt;
    c_username character varying(30) NOT NULL,&lt;br /&gt;
    c_likes_salty_food character(1) NOT NULL DEFAULT &amp;#039;N&amp;#039;::bpchar,&lt;br /&gt;
    CONSTRAINT t_preferences_pk PRIMARY KEY (c_username),&lt;br /&gt;
    CONSTRAINT t_preferences_ck_likes_salty_food CHECK c_likes_salty_food = &amp;#039;Y&amp;#039;::bpchar OR c_likes_salty_food = &amp;#039;N&amp;#039;::bpchar) &lt;br /&gt;
    )&lt;br /&gt;
  WITHOUT OIDS;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So a user can prefer to have an extra salt (character &amp;lt;code&amp;gt;Y&amp;lt;/code&amp;gt;) or a normal amount of salt (character &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt;) in his food.&lt;br /&gt;
&lt;br /&gt;
And in the front end we would like to have a checkbox that shows &amp;#039;&amp;#039;&amp;#039;Salty&amp;#039;&amp;#039;&amp;#039; if checked or &amp;#039;&amp;#039;&amp;#039;Normal&amp;#039;&amp;#039;&amp;#039; if unchecked.&lt;br /&gt;
&lt;br /&gt;
To bind a checkbox to this column is a two step procedure:&lt;br /&gt;
&lt;br /&gt;
First, you&amp;#039;d create a property (let&amp;#039;s call it &amp;lt;code&amp;gt;LikesSalt&amp;lt;/code&amp;gt; in the bizobj that would handle the conversion, and bind to that property. The bizobj class would contain the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def _getLikesSalt(self):&lt;br /&gt;
    YorN = self.getFieldVal(&amp;quot;c_likes_salty_food&amp;quot;)&lt;br /&gt;
    l_value = (YorN == &amp;quot;S&amp;quot;)&lt;br /&gt;
    print &amp;quot;getLikesSalt: YorN =&amp;quot;, YorN , &amp;quot; value=&amp;quot;, l_value&lt;br /&gt;
    return l_value&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _setLikesSalt(self, val):&lt;br /&gt;
    YorN = {True: &amp;quot;Y&amp;quot;, False: &amp;quot;N&amp;quot;}[val]&lt;br /&gt;
    print  &amp;quot;setLikesSalt: YorN =&amp;quot;, YorN &lt;br /&gt;
    self.setFieldVal(&amp;quot;c_likes_salty_food&amp;quot;, YorN)&lt;br /&gt;
&lt;br /&gt;
LikesSalt = property(_getLikesSalt, _setLikesSalt, None,&lt;br /&gt;
    _(&amp;quot;Intermediate to convert the Y/N column to a boolean  (bool)&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Second, you need to open the [[ClassDesigner]] and set the [[DataSource]] property to a reference to the bizobj, and [[DataField]] property to &amp;#039;&amp;#039;&amp;#039;LikesSalt&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Questions for Ed by Luca: ====&lt;br /&gt;
&lt;br /&gt;
1) What is the dabo way to get a reference to the bizobj from the class designer?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color: blue;&amp;quot;&amp;gt;ed: Just type the [[DataSource]] of the bizobj you want. The framework handles resolving that.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2) If &amp;lt;code&amp;gt;A&amp;lt;/code&amp;gt; choice is the right one, how can I force a refresh/redraw of the checkbox to show the mark visible to the user? (I mean [X]? flagged or [ ]? unflagged)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color: blue;&amp;quot;&amp;gt;ed: I&amp;#039;m not sure what you mean. If the current record&amp;#039;s value for &amp;lt;code&amp;gt;LikesSalt&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, the calling &amp;lt;code&amp;gt;form.update()&amp;lt;/code&amp;gt; will update any data-bound controls.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) How can I show in the caption of the checkbox the string &amp;quot;&amp;#039;&amp;#039;&amp;#039;Salty&amp;#039;&amp;#039;&amp;#039;&amp;quot; or &amp;quot;&amp;#039;&amp;#039;&amp;#039;Normal&amp;#039;&amp;#039;&amp;#039;&amp;quot;? Should I intercept the click on the checkbox and change the caption? There is no way to say to the [[dCheckbox]] to use these strings using the class designer?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color: blue;&amp;quot;&amp;gt;ed: You can set the initial value using the prop sheet, but there is no native function in a checkbox to change caption when the value changes. You&amp;#039;ll have to write some code and bind it to the &amp;lt;code&amp;gt;ValueChanged&amp;lt;/code&amp;gt; event, since the value can change programmatically (from navigation, etc.) as well as from clicking.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
luca: I intercepted the &amp;lt;code&amp;gt;onValueChanged&amp;lt;/code&amp;gt; method, and, when I click on the checkbox, the caption gets changed, but this doesn&amp;#039;t happen if I switch to another record pressing a button that invokes a prior() or next() button. Is this a consequence of question 1?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color: blue;&amp;quot;&amp;gt;ed: Are you calling &amp;lt;code&amp;gt;self.Form.next()&amp;lt;/code&amp;gt; in the button? That should issue the call to the form&amp;#039;s &amp;lt;code&amp;gt;update()&amp;lt;/code&amp;gt; method.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4) Is there any way to force a &amp;quot;code generation&amp;quot; of the form as it&amp;#039;s been viewed by the [[ClassDesigner]]? Inspecting this source could be very helpful to understand the inner working of the class designer/dabo runtime, and I think it could avoid many questions...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color: blue;&amp;quot;&amp;gt;ed: It doesn&amp;#039;t generate code that is very helpful or elegant, and it does it on the fly, so the result from run to run can change. But if you really want to see it, go to &amp;lt;code&amp;gt;dabo/lib/DesignerXmlConverter.py&amp;lt;/code&amp;gt;, and uncomment line 73.&amp;lt;/span&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ed</name></author>
	</entry>
</feed>