From: Leanan Sidhe 
  I have heard that TIMTOWTDI, but the only suggestions I've seen were in 
regards to password fields and using DBIx::Class::DigestColumns.  I need to do 
some mathematical conversions on columns before the data is put into the 
database.  I'm trying to do it this way:



    my $elements_to_convert = $form->get_all_elements({ type => 'Text'});

    foreach my $element (@{$elements_to_convert}) {
      if ($element->attributes->{'class'} =~ /I-want-to-convert-this/){
        my $nested_name = $element->nested_name;
        my $field_value = $form->param_value($nested_name);
        $element->default(($field_value * $conversion));
      }
    }

  However, nothing is working.  I've tried $element->default($my_new_value), 
$form->default_values($nested_name => $my_new_value), 
$form->default_values({$nested_name => $my_new_value}) and 
$form->add_valid($nested_name, $my_new_value}).  None of these seemed to work.

  Is add_valid only for adding new fields?  The doc says "The provided value 
replaces any current value for the named field." which suggests to me that if I 
have a field foo, $form->add_valid(foo, $new_value) should work.  But then I 
saw this in HTML::FormFu::Model::DBIC: "add_valid works for fieldnames that 
don't exist in the form." Which suggest that it only works to add new valid 
fields.  I'm a little confused by this.

  Ideas?  Thanks!


  I was also very confused about that part of the POD documentation and I found 
that the most easy solution is to use:



  $c->req->param('password', sha1_hex($c->req->param('password')));
  $form->process;


  With other words, change the value of $c->req->param('field_name') and not 
the value of an element in $form.

  Then do $form->process.



  This way isn't recommended because this type of change should be done in the 
DBIC class and not in the controller, for beeing able for example to do the 
same thing from an external program that has nothing to do with the Catalyst 
framework, but I don't know how to do this in the class file, because I haven't 
seen any example of doing this.

  Maybe DBIx::Class::DigestColumns can be extended to accept other type of 
changes than just digests...



  Octavian


_______________________________________________
HTML-FormFu mailing list
HTML-FormFu@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu

Reply via email to