use strict; use warnings; use Test::More; use HTML::FormHandler::Test; { package MyApp::Form::CtrlStates::Theme; use Moose::Role; with 'HTML::FormHandler::Widget::Theme::Bootstrap'; sub build_form_tags {{ after_start => '
', }} sub build_update_subfields {{ focusedInput => { element_class => ['input-xlarge', 'focused'] }, uneditableInput => { element_class => ['input-xlarge', 'uneditable-input'] }, disabledInput => { element_class => ['input-xlarge'], element_attr => { placeholder => 'Disabled input here…' } }, optionsCheckbox2 => { element_class => ['checkbox'], option_label => 'This is a disabled checkbox' }, inputError3 => { wrapper_class => ['success'], tags => { after_element => qq{\nWoohoo!} } }, selectError => { wrapper_class => ['success'], tags => { after_element => qq{\nWoohoo!} } }, form_actions => { do_wrapper => 1, do_label => 0 }, 'form_actions.save' => { widget_wrapper => 'None', element_class => ['btn', 'btn-primary'] }, 'form_actions.cancel' => { widget_wrapper => 'None', element_class => ['btn'] }, }} } { package MyApp::Form::CtrlStates; use HTML::FormHandler::Moose; extends 'HTML::FormHandler'; with 'MyApp::Form::CtrlStates::Theme'; has '+name' => ( default => 'test_form' ); has_field 'focusedInput' => ( default => 'This is focused…', label => 'Focused input' ); has_field 'uneditableInput' => ( type => 'NonEditable', label => 'Uneditable input', value => 'Some value here', ); has_field 'disabledInput' => ( disabled => 1, label => 'Disabled input' ); has_field 'optionsCheckbox2' => ( type => 'Checkbox', checkbox_value => "option1", disabled => 1, label => 'Disabled checkbox' ); has_field 'inputError1' => ( validate_method => \&validate_ie1, label => 'Input with warning' ); has_field 'inputError2' => ( validate_method => \&validate_ie2, label => 'Input with error' );; has_field 'inputError3' => ( label => 'Input with success' );; has_field 'selectError' => ( type => 'Select', label => 'Select with success', options => [{ value => 1, label => '1' }, { value => 2, label => '2' }, { value => 3, label => '3'}, { value => 4, label => '4' }, { value => 5, label => '5' } ], ); has_field 'form_actions' => ( type => 'Compound' ); has_field 'form_actions.save' => ( widget => 'ButtonTag', type => 'Submit', value => 'Save changes' ); has_field 'form_actions.cancel' => ( widget => 'ButtonTag', type => 'Reset', value => 'Cancel' ); sub validate_ie1 { my $self = shift; # self is the field here $self->add_warning('Something may have gone wrong'); } sub validate_ie2 { my $self = shift; $self->add_error('Please correct the error'); } } my $form = MyApp::Form::CtrlStates->new; my $params = $form->fif; $params->{inputError1} = 'entry'; $params->{inputError2} = 'xxx'; $params->{inputError3} = 'success'; $form->process( $params ); my $expected = '