diff --git a/lib/Cro/WebApp/Form.pm6 b/lib/Cro/WebApp/Form.pm6 index 3e64264..c994cff 100644 --- a/lib/Cro/WebApp/Form.pm6 +++ b/lib/Cro/WebApp/Form.pm6 @@ -13,6 +13,7 @@ my role FormProperties { has Int $.webapp-form-maxlength is rw; has Real $.webapp-form-min is rw; has Real $.webapp-form-max is rw; + has Bool $.webapp-form-ro is rw; has List @.webapp-form-validations; } @@ -155,6 +156,11 @@ multi trait_mod:(Attribute:D $attr, Real :$min! --> Nil) is export { $attr.webapp-form-min = $min; } +multi trait_mod:(Attribute:D $attr, Bool :$form-read-only! --> Nil) is export { + ensure-attr-state($attr); + $attr.webapp-form-ro = $form-read-only; +} + #| Set the maximum numeric value of an input field multi trait_mod:(Attribute:D $attr, Real :$max! --> Nil) is export { ensure-attr-state($attr); @@ -292,9 +298,11 @@ role Cro::WebApp::Form { my %form-data := $body.hash; my %values; my %unparseable; + for self.^attributes.grep(*.has_accessor) -> Attribute $attr { my $name = $attr.name.substr(2); my $value := %form-data{$name}; + if $attr.type ~~ Positional { my $value-type = $attr.type.of; my @values := $value ~~ Cro::HTTP::MultiValue ?? $value.list !! @@ -393,6 +401,7 @@ role Cro::WebApp::Form { (with $attr.?webapp-form-placeholder { placeholder => $_ }), required => ?$attr.required, type => $control-type, + read-only => $attr.?webapp-form-ro, %properties; if %validation-by-control{$name} -> @errors { self!set-control-validation(%control, @errors) @@ -487,7 +496,9 @@ role Cro::WebApp::Form { method !add-current-value(Attribute $attr, %properties? is copy) { with $attr.get_value(self) { when Date { %properties = .yyyy-mm-dd; } - when DateTime { %properties = .Str; } + + when DateTime { %properties .= Str } + default { %properties = $_; } } orwith %!unparseable{$attr.name.substr(2)} { diff --git a/resources/prelude.crotmp b/resources/prelude.crotmp index 86a2b77..dbe2cc6 100644 --- a/resources/prelude.crotmp +++ b/resources/prelude.crotmp @@ -46,7 +46,7 @@ > - <&str-opts($_)>.defined()> value="<.value>"> + disabled id="<.name>"<&control-class($_, $input-control-class, :$is-invalid-class)><&str-opts($_)>.defined()> value="<.value>"> <&control-help($_, :$help-class)> <&control-validation-message($_, :$invalid-feedback-class)> @@ -54,7 +54,7 @@ > - <&str-opts($_)>> + disabled id="<.name>"<&control-class($_, $input-control-class, :$is-invalid-class)><&str-opts($_)>> <&control-help($_, :$help-class)> <&control-validation-message($_, :$invalid-feedback-class)> @@ -62,7 +62,7 @@ > - <&num-opts($_)>.defined()> value="<.value>"> + disabled id="<.name>"<&control-class($_, $input-control-class, :$is-invalid-class)><&num-opts($_)>.defined()> value="<.value>"> <&control-help($_, :$help-class)> <&control-validation-message($_, :$invalid-feedback-class)> @@ -70,7 +70,7 @@ > - .defined()> value="<.value>"> + disabled id="<.name>"<&control-class($_, $input-control-class, :$is-invalid-class)>.defined()> value="<.value>"> <&control-help($_, :$help-class)> <&control-validation-message($_, :$invalid-feedback-class)> @@ -78,7 +78,7 @@ > - > + disabled id="<.name>"<&control-class($_, $input-control-class, :$is-invalid-class)>> <&control-help($_, :$help-class)> <&control-validation-message($_, :$invalid-feedback-class)> @@ -86,14 +86,14 @@ > - + <&control-help($_, :$help-class)> <&control-validation-message($_, :$invalid-feedback-class)> > - > checked> + disabled id="<.name>"<&control-class($_, $check-control-class, :$is-invalid-class)>> checked> <&control-help($_, :$help-class)> <&control-validation-message($_, :$invalid-feedback-class)> @@ -102,7 +102,7 @@ > - multiple name="<.name>" disabled id="<.name>"<&control-class($_, $input-control-class, :$is-invalid-class)>> <@options : $opt>