On Wednesday 26 September 2007 14:27:22 Carl Franks wrote:
> On 26/09/2007, Mario Minati <[EMAIL PROTECTED]> wrote:
> > On Wednesday 26 September 2007 12:57:27 Josef Chladek wrote:
> > > Am 26.09.2007 um 12:45 schrieb Carl Franks:
> > > > On 26/09/2007, Josef Chladek <[EMAIL PROTECTED]> wrote:
> > > >> hello again,
> > > >>
> > > >> in my code:
> > > >>
> > > >> my $nick = $c->stash->{form}->get_field('nickname');
> > > >> $nick->value($c->stash->{form}->param('username')) if length($c-
> > > >>
> > > >>> stash->{form}->param('nickname')) == 0;
> > > >>
> > > >> $c->stash->{form}->process;
> > > >> $c->log->debug($c->stash->{form}->get_field('nickname')->value);
> > > >>
> > > >> in the debug output I can see that nickname is set to the username,
> > > >> when the form is rendered, the nickname field stays empty - what am
> > > >> I doing wrong?
> > > >
> > > > For text fields, value() is just an alias to default() - and default
> > > > is ignored when rendering after a submission.
> > > >
> > > > I think either of these solutions should work:
> > > >
> > > >     $nick->default( $form->param('username') );
> > > >     $nick->force_default(1);
> > > >
> > > > or
> > > >
> > > >     $form->add_valid( 'nickname', $form->param('username') );
> > > >
> > > > Carl
> > >
> > > the latter I'd tried before (and did not work), the solution with
> > > force_default did it.
> >
> > You have to change
> > $c->stash->{form}->input->{'nickname' }
> > to get your behaviour, but that is a hack as it relies on the internal
> > behaviour of FormFu, which might change.
> >
> > So Carl's way is nicer.
> >
> > In general I think we should create a filter that can do this work for
> > fields that takes the value of an other field, as this is a common task.
> >
> > And we could create a shortcut like 'overwrite_value' to do this task in
> > one function.
>
> I think a filter would be a good idea.

I just uploaded a new CopyValue filter to svn included a test and some docs.

There is on caveat:
If the value of the original field contains an invalid value (a value that
will be constrained through a constraint) this invalid value will be choosen
for this field (the field with CopyValue filter).

So the user has to change two fields or you remove the invalid value in a
custom constraint.


This brought me to the idea that constraints with 'clear_value' set to 1 could 
remove their according input / param.

We can think about this later on, as it might be tricky to handle errors which 
are displayed on other fields, like with the DependOn and MinMaxField 
constraint.

Greets,
Mario

_______________________________________________
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