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

A place for users and developers of the Xataface to discuss and receive support.

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

Postby marksawers » Wed Apr 16, 2008 1:23 pm

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!
marksawers
 
Posts: 7
Joined: Wed Apr 16, 2008 1:09 pm
Location: Fairfield, CT

Postby shannah » Wed Apr 16, 2008 2:08 pm

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'.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

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

Postby marksawers » Wed Apr 16, 2008 2:28 pm

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.
marksawers
 
Posts: 7
Joined: Wed Apr 16, 2008 1:09 pm
Location: Fairfield, CT

Postby mikep » Tue Jun 23, 2009 8:45 am

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
mikep
 
Posts: 44
Joined: Fri Apr 24, 2009 2:21 pm

Postby shannah » Tue Jun 23, 2009 10:07 am

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...
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 26 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved