[html-formfu] update Checkbox field problem
    Stephen Shorrock 
    stephen.shorrock at googlemail.com
       
    Fri Mar 12 12:55:31 GMT 2010
    
    
  
Dear Carl,
I was wondering whether you would be able to offer some insight into 
what the issue with my code could be:
I'm attempting to update the value of a check box following a form submit:
Along the lines of
#values hardcoded for example
if(defined($c->stash->{form}->get_field("keep_row"))){
                print STDERR $form->get_field("keep_row)."\n";
            $form->get_field("keep_row")->value("118");
                print STDERR $form->get_field("keep_row")."\n";
            $form->get_field("keep_row")->add_attrs({checked=>'checked'});
                print STDERR $form->get_field("keep_row")."\n";
}
When the checkbox has been checked the checked attribute is removed:
<div class="checkbox"><input name="keep_row" type="checkbox" value="1"  
checked="checked" /></div>
<div class="checkbox"><input name="keep_row" type="checkbox" value="118" 
/></div>
<div class="checkbox"><input name="keep_row" type="checkbox" value="118" 
/></div>
However when the checkbox has not been selected and I want to update 
then I am able to add the checked attribute and modify the value (I'm 
essentially populating the form with database defaults).
<div class="checkbox"><input name="keep_row" type="checkbox" value="1"  
/></div>
<div class="checkbox"><input name="keep_row" type="checkbox" value="118" 
/></div>
<div class="checkbox"><input name="keep_row" type="checkbox" 
value="118"  checked="checked" /></div>
I've tried to debug by writing a test (reading from a yml) with checkbox 
attribute set or unset in the yml file, but this seems to work fine.
Is modifying the field and its attributes the correct way for me to 
build the form, or are there some quirks because I'm trying to modify 
already processed fields? No Filters/Constraints/Plugins exist on the 
Checkbox field
Thanks in advance
Stephen
    
    
More information about the HTML-FormFu
mailing list