Skip to content

Commit

Permalink
Pass further data for component renderer to use
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed May 20, 2022
1 parent 53727e9 commit f97276f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
27 changes: 27 additions & 0 deletions lib/Cro/WebApp/Form/Component.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,35 @@ class Cro::WebApp::Form::Component::Data {
#| The name of the control.
has Str $.name is required;

#| The label of the control.
has Str $.label is required;

#| Help message for the control, if any.
has $.help;

#| Validation errors, if any.
has @.validation-errors;

#| The current value of the control, if any.
has $.value;

#| The CSS class for input groups, if any.
has $.input-group-class;

#| The CSS class for labels, if any.
has $.input-label-class;

#| The CSS class for help messages, if any.
has $.help-class;

#| The CSS class for validation errors against a particular component, if any..
has $.invalid-feedback-class;

#| The CSS class for controls that are invalid, if any..
has $.is-invalid-class;

#| The CSS class for an input control, if any..
has $.input-control-class;
}

#| The base role of all custom form components.
Expand Down
7 changes: 6 additions & 1 deletion resources/prelude.crotmp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@
<div<&class($input-group-class)>>
<label for="<.name>"<&class($input-label-class)>><.label></label>
</?>
<&HTML-AND-JAVASCRIPT(.<custom-component>.render(.<custom-data>.new(:name(.name), :value(.value))))>
<&HTML-AND-JAVASCRIPT(.<custom-component>.render(.<custom-data>.new(
:name(.<name>), :label(.<label>), :help(.<help>), :validation-errors(.<validation-errors>), :value(.<value>),
:input-group-class($input-group-class), :input-label-class($input-label-class),
:help-class($help-class), :input-control-class($input-control-class),
:invalid-feedback-class($invalid-feedback-class), :is-invalid-class($is-invalid-class)
)))>
<?{ .<custom-component>.default-wrapper() }>
<&control-help($_, :$help-class)>
<&control-validation-message($_, :$invalid-feedback-class)>
Expand Down
2 changes: 1 addition & 1 deletion t/form-custom-component.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use Test;
is-deeply .<custom-data>, Cro::WebApp::Form::Component::Data, 'Also given component data type object';

my Str $rendered;
lives-ok { $rendered = .<custom-component>.render(.<custom-data>.new(:name('test'), :value('v'))) },
lives-ok { $rendered = .<custom-component>.render(.<custom-data>.new(:name('test'), :label('Test'), :value('v'))) },
'Can render template component';
ok $rendered.contains('<input type="text" name="test" value="v">'),
'Rendered as expected';
Expand Down

0 comments on commit f97276f

Please sign in to comment.