On 15 October 2010 11:23, Charlie Garrison <garri...@zeta.org.au> wrote: > Good evening, > > Sorry for taking so long to get back to this; had to find time to > investigate it more. > > On 2/09/10 at 9:50 PM +0100, Carl Franks <fireart...@gmail.com> wrote: > >> On 26 August 2010 18:02, Charlie Garrison <garri...@zeta.org.au> wrote: >>> >>> I've got a read-only field (from HTML::FormFu::Model::DBIC) which is >>> losing >>> the displayed value after form is submitted. I've tried various >>> combinations >>> of force_default, retain_default, etc but don't seem to be able to get >>> the >>> right configuration. >> >> Hi, >> Sorry, I'm not clear on exactly what behaviour you're seeing, and what >> you're expecting - can you clarify? > > I'm using a field of type Label to display field/value for current record, > eg: > > elements: > - type: Label > name: username > label: User Name > > When the form first loads `$form->model->default_values($user)` the username > is displayed as expected in the html page. After submitting the form, the > username is blank in the html page. > >>> All other fields in the form get saved to the db as expected. Am I doing >>> something wrong in the config or controller action? >> >> Are you expecting the read_only field value to be saved to the database? > > No, I'm expecting the form field defined as type Label to retain it's value > after a form submission. > >> All the read_only option does is cause update/create to not update the >> column corresponding to that field. >> >> In the most basic use, it doesn't need force_default or retain_default >> to be set - so can you explain what you're wanting that to do? > > Hopefully I've clarified above what I'm wanting. I've figured out why the > Label field is losing its value. But I'm not sure how to fix it or how I > should be using FormFu instead. > > The cause of the problem is simple, there is no `username` value being > submitted with the form since there is no html <input type=hidden> for the > Label field. The form is populated with submitted data which doesn't contain > the username, so therefore username appears blank. > > I tried creating a Hidden field type named `username`, but I get the > following error when submitting the form: > > Can't locate object method "delete_nested_hash_value" via package > "HTML::FormFu" at /Library/Perl/5.8.8/HTML/FormFu/Element/Label.pm line 77. > > I'm guessing that is due to two elements with the same name. > > > It's quite likely I've got the wrong config/setup, but I'm not sure what I > should be doing. The only solution I've thought of is to set the > default_value for `username` field regardless of whether the form has been > submitted. That doesn't seem like the right solution though. Would changing > the Label element to optionally include a hidden field be a workable > solution? > > > To simplify this issue, is there a 'correct' way to display a > static/read-only value (eg. Label element) which is retained after > submitting a form?
Hi Charlie, It turned out that the "delete_nested_hash_value" error was a bug - it should actually have been trying to call the method named "delete_nested_hash_value". However, that still wouldn't have fixed things for you, because the Label element was deliberately deleting the submitted value, as a security precaution, because the Label element doesn't want someone submitting values for what's not really a form field. So I've now added a check - and if there's another field on the form with the same name as the Label element, the submitted value won't be deleted - so it should now work for you using a Hidden field with the same name as the Label element. The fix is in svn, and will be included in the next cpan release. Cheers, Carl _______________________________________________ HTML-FormFu mailing list HTML-FormFu@lists.scsys.co.uk http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu