Page 1 of 1
widget:type = checkbox for booleans with 0 or 1 values

Posted:
Wed Apr 16, 2008 1:23 pm
by marksawers
My database uses 0 and 1 integer values for booleans. Can I use the checkbox widget type? If it's unchecked, the form complains on a non-null field.
As an alternative, I tried radio, even though it's not listed in the "Gettting started..". I see one option with "Array" as the label. What's the syntax for radio widget type?
Thanks!

Posted:
Wed Apr 16, 2008 2:08 pm
by shannah
Is there any significance to a NULL value in your database for this column? I.e. does the field need to be not null?
You could add a beforeSave() trigger to ensure that when the field is not checked it will be stored as a 0 instead of null:
- Code: Select all
function beforeSave(&$record){
if (!$record->val('myfield') ) $record->setValue('myfield', 0);
}
This assumes that your boolean field is named 'myfield'.
widget:type = checkbox for booleans with 0 or 1 values

Posted:
Wed Apr 16, 2008 2:28 pm
by marksawers
Yes, all these fields are declared not null and Xataface marks it as required. This is a nice time-saving feature, but in this case I think we need to override it. I don't think it's executing the beforeSave() if the box is unchecked. I get the javascript popup complaining that the field is required.

Posted:
Tue Jun 23, 2009 8:45 am
by mikep
I am having the same trouble with radio buttons. I get a single radio button labeled "Array". Is there a special syntax for defining radio buttons?
Mike

Posted:
Tue Jun 23, 2009 10:07 am
by shannah
Ah... yes. Despite the fact that HTML_QuickForm supports radio buttons, I have never gotten around to supporting them in xataface because functionally they are the same as a select list. Some day...