default values for checkbox groups

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

default values for checkbox groups

Postby 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.
S. T. Stoddard
ststoddard
 
Posts: 56
Joined: Mon Nov 05, 2007 4:10 pm
Location: Davis, CA

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

Postby 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.
S. T. Stoddard
ststoddard
 
Posts: 56
Joined: Mon Nov 05, 2007 4:10 pm
Location: Davis, CA

Postby 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
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