Page 1 of 1

Testing, getting and setting checkbox values

PostPosted: Fri Aug 06, 2010 3:20 pm
by Martin Dowse
Hi

what is the recommended way of testing, getting and setting values stored in widget:type=checkbox fields? Is there a way to use $record->valueChanged, $record->val and $record->setValue with individual fields within the checkbox array?

Thanks

Martin

PS: Apologies if this post turns up twice - I thought I had posted it last night but I can't see it now so here it is again.

Re: Testing, getting and setting checkbox values

PostPosted: Wed Aug 11, 2010 10:44 am
by shannah
I always forget exactly how they're stored... I think these fields are stored as associative arrays. The best way to check is to do a print_r on output of the val() method for the particular field.
e.g.
Code: Select all
print_r($record->val('my_checkbox_field'));


The valueChanged() method will return true if ANY of the values have changed. You can compare the changes by comparing getSnapshot() with getValues().

e.g.
Code: Select all
$snapshot = $record->getSnapshot();
$current = $record->getValues();
$oldFieldVal = $snapshot['my_field'];
$currFieldVal = $current['my_field'];


or something along those lines.

-Steve

Re: Testing, getting and setting checkbox values

PostPosted: Wed Aug 11, 2010 12:51 pm
by Martin Dowse
Thanks - that will do the job.