[html-formfu] Default Values

Robyn Jonahs learn.catalyst at gmail.com
Tue Apr 17 15:20:41 GMT 2012


On Tue, Apr 17, 2012 at 10:57 AM, Robyn Jonahs <learn.catalyst at gmail.com>wr=
ote:

> On Tue, Apr 17, 2012 at 10:41 AM, Carl Franks <fireartist at gmail.com>wrote:
>
>> On 17 April 2012 14:33, Robyn Jonahs <learn.catalyst at gmail.com> wrote:
>> > Hi,
>> >
>> > I am using Catalyst 5.90011 with HTML::FormFu::Model::DBIC and mysql
>> >
>> > I am having a problem where I can't get the default value set in mysql
>> and
>> > also in my Catalyst Schema::Result to get inserted into the database. =
It
>> > sticks
>> > a null value in rather than my default value. For example, this is a
>> > checkbox
>> >
>> > In the Schema::Result::File.pm
>> >
>> >   "trip",
>> >   { data_type =3D> "tinyint", default_value =3D> 0, is_nullable =3D> 1=
 },
>> >
>> > In the YAML form definition
>> >     # Trip?
>> >     - type: Checkbox
>> >       name: trip
>> >       label: Trip Expense?
>> >
>> > I get an empty checkbox with a new form, but if I don't check it, then
>> it
>> > gets set in the database as Null
>> >
>> > If I check it and uncheck it, it gets put into the database as Null
>> >
>> > If I check it, it gets put in the database as 1
>> >
>> > Why won't it insert the default value of 0?
>>
>> I think this would be fixed by either setting the DBIC column to
>> is_nullable =3D> 0
>> or by adding a "default: 0" to the formfu element definition.
>>
>> If you don't want to change is_nullable, and the "default: 0" alone
>> doesn't work, try also adding "retain_default: 0" - it's been a long
>> time since I've used this stuff, and can't remember all the details.
>>
>> Carl
>>
>> _______________________________________________
>> HTML-FormFu mailing list
>> HTML-FormFu at lists.scsys.co.uk
>> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>>
>
> Ah, thanks. That fixed it.
>
> I set it to not null in the mysql definition for the column and left the
> FormFu YAML alone.
> This of course set the schema result correctly after I used the create
> script to update.
>
> I had removed those not nulls since I thought that default would take care
> of setting
> a value and thought it was not required and was redundant.
>
> R
>
>
>
Just as an addendum... I also had enum values in the mysql table that also
set a default and also DID NOT have the not null set. They inserted a
default value into the database with the update and simple FormFu YAML
definition.

HOWEVER... I just noticed that the Form is not displaying the default
value....

Q1: How can I get FormFu to show the default as the selected value?

Q2: Can I have it automatically fill the enum values into a select field? I
did not try to do this in my controller and send it to the options of the
element as done in the Catalyst example since I was having troubles
somewhere with getting those to update well and have set that aside for the
moment. I was not sure how to do this... but looking here I may just need
to somehow send the type.extra.list as the options in my controller?

        my @TypeList =3D
$c->model("DB::Expense")->get_field_values(type.extra);
        my $TypeSelectOptions =3D $form->get_element({name =3D> 'type'});
        $TypeSelectOptions ->options(\@lTypeList);

I am certain that the first line is wrong but I have no idea what I can
call on $c-> model to get the enum list out. I am still learning so any
help is very much appreciated.


In mysql I have...
  type          enum('business', 'personal', 'reimbursed') default
'personal',


In the Schema::Result::  I have
  "type",
  {
    data_type =3D> "enum",
    default_value =3D> "personal",
    extra =3D> { list =3D> ["business", "personal", "reimbursed"] },
    is_nullable =3D> 1,
  },


And in the YAML form definition I have
    # Type
    # Manually set the select items for enum types? No auto fill?
    - type: Select
      name: type
      label: Type
      container_attributes:
        title: Reimbursed is for things we buy for clients that has been
reimbursed financially.
      options:
        - ['business', 'Business']
        - ['personal', 'Personal']
        - ['reimbursed', 'Reimbursed']
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20120417/22=
08fb48/attachment-0001.htm


More information about the HTML-FormFu mailing list