There’s no special magic in the view that pre-checks a checkbox. (That
would be nice!) Here’s what I usually add to my controller:
$foo->bar_checked = ($foo->bar > 0) ? ' checked="checked"' : '';
(add that line before the call to render_partial)
And then in the view, I simply add that variable into the checkbox
like this:
<input type="checkbox" name="bar" id="bar" value="1"<?=$bar_checked?> />
One other thing you need to take care of with checkboxes is the un-
check behavior. I usually add this inside the ‘edit’ $verb vase, after
the populate(clean($_POST)) line:
if($foo->bar > 0 && !isset($_POST['bar'])) $foo->bar = 0;
Otherwise, you will only be able to check the checkbox, not un-check
it later.
Walter
On Aug 20, 2009, at 6:11 PM, Todd wrote:
The approval checkbox now validates. On the admin side of things I
have a pre-populated duplicate of the client-side form so I can edit
entries. I was expecting the approval checkbox to be “checked” but
it remains unchecked despite a positive value being passed to the
db. Is it possible to have it already enabled? Perhaps my value
setting is incorrect? The only way I can get a value to display is
by using a text-field, not a checkbox.
Todd
On Aug 18, 2009, at 2:00 PM, Walter Lee Davis wrote:
Assuming that your checkbox is named approval, has a value of some
sort (1 will do), and that there is a field in the database called
approval, and you have used populate() or another method to set the
value of approval to the value of $_POST[‘approval’], then this
should just work.
dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options
dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options