default values for checkbox groups

Archived from the Xataface Users forum.

ststoddard — Tue Nov 06, 2007 5:24 am

I have a few instances of checkbox groups I use for multi-value fields, e.g.:

Cooking method:

[ ] gas

[ ] electric

[ ] charcoal

[ ] wood

Several of which can be selected. These get loaded into a varchar(x) field. Works perfect.

However, I can’t set default values. If I attempt:

[cooking_method]

Default = gas

*All* of the values are selected, not just gas. If I attempt the same in MySQL or in the DelegateClass, same story.

I am contemplating complex select lists to work around this as I have a premium on data entry speed, and defaults help a lot with this.

Also, on a related note, is there no way to layout the checkboxes in-line as opposed to vertical? Rather, an easy way? I have no skills with HTML nor CSS, but can hack away with some direction.


shannah — Tue Nov 06, 2007 5:55 am

Multi-value fields have an internal structure of an array.

Try

Code: Select all
function cooking__default(){     return array('gas'); }

ststoddard — Tue Nov 06, 2007 6:09 am

I tried:

Code: Select all
function sewage__default() {       return array('SEWER');    }

It didn’t work. Form loads with no checkbox marked.

I tried a couple of fields.


shannah — Tue Nov 06, 2007 12:59 pm

Actually had to look at the code for this one.

For checkbox groups, the defaults should actually be of the form:

array(value1=>1,value2=>2);

e.g.

Code: Select all
function sewage__default() {       return array('SEWER'=>1); }

This is because the xxx__default() results are fed directly into HTML_QuickForm’s setDefaults() method which accepts parameters in a slightly different form than if they were going to a Dataface_Record object.

-Steve