[html-formfu] Constraint "Required" with condition "when" doesn't
work in apache-style config
Christoph Metz
mail-lao at web.de
Sat Nov 29 12:35:19 GMT 2008
Christoph Metz wrote:
> Carl Franks wrote:
>> 2008/11/28 Christoph Metz <mail-lao at web.de>:
>>
>>> Carl Franks wrote:
>>>
>>>> 2008/11/28 Christoph Metz <mail-lao at web.de>:
>>>>
>>>>
>>>>> using an Require constraint whith the "when" condition doesn't
>>>>> work fine
>>>>> for
>>>>> me :/
>>>>>
>>>>> <element>
>>>>> type Select
>>>>> name kompetenzfeld_id
>>>>> <constraint>
>>>>> type Required
>>>>> <when>
>>>>> field extern
>>>>> values 0
>>>>> </when>
>>>>> </constraint>
>>>>> </element>
>>>>>
>>>>>
>>>>> without the "<when>" part the Required constrain works correctly,
>>>>> maybe
>>>>> the
>>>>> syntax of my conf isn't correct, but this was the only variant,
>>>>> (config-loader) formfu accepted so far...
>>>>>
>>>>>
>>>> That config seems to work, looking at a dumped $form, so the problem
>>>> must either be a misunderstanding of how it's meant to work, or a bug.
>>>> Note that the when() doesn't yet support nested params, such as
>>>> "foo.bar".
>>>>
>>>> Can you write a failing test file, that demonstrates what you expect
>>>> to happen, to help start to narrow it down?
>>>>
>>>> Cheers,
>>>> Carl
>>>>
>>>> _______________________________________________
>>>> HTML-FormFu mailing list
>>>> HTML-FormFu at lists.scsys.co.uk
>>>> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>>>>
>>>>
>>>>
>>> thanks carl,
>>>
>>> the radio-button and the field asking for it with "when()" are
>>> nested in 2
>>> divs... damn. Are there any other possibilities to do this kind of
>>> stuff,
>>> without validating each param by myself AND with the ability to
>>> access these
>>> magic method across blocks, like some divs?
>>>
>>
>> If it's just normal nested Blocks without a nested_name set, then it
>> should be fine.
>> It's only nested-params that don't work - that's when an outer block
>> has a nested_name(), such as:
>>
>> type: Block
>> nested_name: foo
>> elements:
>> - type: Text
>> name: bar
>>
>> Which would cause the Text field to actually get the name "foo.bar"
>>
>> Carl
>>
>> _______________________________________________
>> HTML-FormFu mailing list
>> HTML-FormFu at lists.scsys.co.uk
>> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>>
>>
> so, i have created a testfile for the problem, i am using FormFu
> inside the catalyst-framework, Catalyst::Controller::HTML::FormFu is
> Version 0.03004, Catalyst is version 5.7014. so firstly here is the
> controller:
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>
> package MyApp::Controller::test;
>
> use strict;
> use warnings;
> use base qw(Catalyst::Controller::HTML::FormFu);
>
> sub index : Local FormConfig('test/index2.conf'){
> my ( $self, $c ) = @_;
>
> my $form = $c->stash->{form};
> if ($form->submitted_and_valid){
> $c->stash->{message} = "Form sumitted and valid!"; }
> $c->stash->{template} = 'test/index.tt2';
> }
>
> 1;
>
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> the Formfu conf file:
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> indicator submit
>
> <element>
> type Radio
> name additional_infos
> value 1
> label yes
> </element> <element>
> type Radio
> name additional_infos
> value 0
> label no
> checked checked
> </element>
> <element>
> type Text
> name additional
> <constraint>
> type Required
> <when>
> field additional_infos
> values 1
> </when>
> </constraint>
> </element>
>
> <element>
> type Submit
> name submit
> value submit
> </element>
>
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> the template:
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>
> [%- META title = "test" -%]
>
> [% form %]
>
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> the catalyst-debug form-dump:
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>
> form => bless({
> _elements => [
> bless({
> _constraints => [],
> _deflators => [],
> _errors => [],
> _filters => [],
> _inflators => [],
> _plugins => [],
> _transformers => [],
> _validators => [],
> attributes => {},
> comment_attributes => {},
> container_attributes => {},
> container_tag => "div",
> field_filename => "input_tag",
> field_type => "radio",
> filename => "input",
> is_field => 1,
> label => "yes",
> label_attributes => {},
> label_filename => "label",
> label_tag => "label",
> name =>
> "additional_infos",
> parent => 'fix',
> reverse_multi => 1,
> stash => {},
> type => "Radio",
> value => 1,
> }, "HTML::FormFu::Element::Radio"),
> bless({
> _constraints => [],
> _deflators => [],
> _errors => [],
> _filters => [],
> _inflators => [],
> _plugins => [],
> _transformers => [],
> _validators => [],
> attributes => { checked
> => "checked" },
> comment_attributes => {},
> container_attributes => {},
> container_tag => "div",
> field_filename => "input_tag",
> field_type => "radio",
> filename => "input",
> is_field => 1,
> label => "no",
> label_attributes => {},
> label_filename => "label",
> label_tag => "label",
> name =>
> "additional_infos",
> parent => 'fix',
> reverse_multi => 1,
> stash => {},
> type => "Radio",
> value => 0,
> }, "HTML::FormFu::Element::Radio"),
> bless({
> _constraints => [
> bless({
> "not"
> => 0,
> parent
> => 'fix',
> type
> => "Required",
> when
> => { field => "additional_infos", "values" => 1 },
> },
> "HTML::FormFu::Constraint::Required"),
> ],
> _deflators => [],
> _errors => [],
> _filters => [],
> _inflators => [],
> _plugins => [],
> _transformers => [],
> _validators => [],
> attributes => {},
> comment_attributes => {},
> container_attributes => {},
> container_tag => "div",
> field_filename => "input_tag",
> field_type => "text",
> filename => "input",
> is_field => 1,
> label_attributes => {},
> label_filename => "label",
> label_tag => "label",
> name => "additional",
> parent => 'fix',
> stash => {},
> type => "Text",
> }, "HTML::FormFu::Element::Text"),
> bless({
> _constraints => [],
> _deflators => [],
> _errors => [],
> _filters => [],
> _inflators => [],
> _plugins => [],
> _transformers => [],
> _validators => [],
> attributes => {},
> comment_attributes => {},
> container_attributes => {},
> container_tag => "div",
> field_filename => "input_tag",
> field_type => "submit",
> filename => "input",
> is_field => 1,
> label_attributes => {},
> label_filename => "label",
> label_tag => "label",
> name => "submit",
> parent => 'fix',
> retain_default => 1,
> stash => {},
> type => "Submit",
> value => "submit",
> }, "HTML::FormFu::Element::Submit"),
> ],
> _models => [],
> _output_processors => [],
> _plugins => [],
> _processed_params => {},
> _valid_names => [],
> attributes => { action => "", method => "post" },
> auto_error_class => "error_%s_%t",
> auto_error_message => "form_%s_%t",
> config_callback => { plain_value => sub { "???" } },
> default_args => { constraints => {}, elements => {} },
> default_model => "DBIC",
> filename => "form",
> indicator => "submit",
> input => {},
> languages => ["en"],
> localize_class => "HTML::FormFu::I18N",
> query => 'fix',
> query_type => "Catalyst",
> render_method => "string",
> stash => { context => 'fix' },
> submitted => "",
> tt_args => 'fix',
> tt_module => "Template",
> }, "HTML::FormFu"),
> template => "test/index.tt2",
> };
> $a->{"__InstancePerContext_159122152"}{c}{stash} = $a;
> $a->{"__InstancePerContext_159122152"}{c}{stats}{stack}[0]{_children}[0]{_parent}
> = $a->{"__InstancePerContext_159122152"}{c}{stats}{stack}[0];
> $a->{"__InstancePerContext_159122152"}{c}{stats}{stack}[0]{_children}[1]{_parent}
> = $a->{"__InstancePerContext_159122152"}{c}{stats}{stack}[0];
> $a->{"__InstancePerContext_159122152"}{c}{stats}{stack}[0]{_children}[2]{_parent}
> = $a->{"__InstancePerContext_159122152"}{c}{stats}{stack}[0];
> $a->{"__InstancePerContext_159122152"}{c}{stats}{tree} =
> $a->{"__InstancePerContext_159122152"}{c}{stats}{stack}[0];
> $a->{form}{_elements}[0]{parent} = $a->{form};
> $a->{form}{_elements}[1]{parent} = $a->{form};
> $a->{form}{_elements}[2]{_constraints}[0]{parent} =
> $a->{form}{_elements}[2];
> $a->{form}{_elements}[2]{parent} = $a->{form};
> $a->{form}{_elements}[3]{parent} = $a->{form};
> $a->{form}{query} = $a->{"__InstancePerContext_159122152"}{c}{request};
> $a->{form}{stash}{context} = $a->{"__InstancePerContext_159122152"}{c};
> $a->{form}{tt_args} =
> $a->{"__InstancePerContext_159122152"}{_html_formfu_config}{constructor}{tt_args};
>
> $a;
>
>
> }
>
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> the error:
>
> indifferent i am chossing the radio button for "yes" or "no" the
> "when()" condition seems to be ignored, the method
> "submitted_and_valid()" never returns true for the form in this case,
> if i am using the Required-constraint without the when() condition all
> works fine.
>
> Greets :)
>
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>
same prob with yaml-conf style:
------------------------------------------------------------------------------------------------------------------------------------------------------
indicator: submit
elements:
- type: Radio
name: additional_infos
value: 1
label: yes
- type: Radio
name: additional_infos
value: 0
label: no
checked: checked
- type: Text
name: additional
constraint:
- type: Required
when:
field: additional_infos
values: 1
- type: Submit
name: submit
value: submit
???
More information about the HTML-FormFu
mailing list