From d24a363a63883cd6c7667b7f60e58ca655a5e607 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Thu, 11 Jul 2024 23:01:45 +0200 Subject: [PATCH] Improve checking of form with optional fields --- src/frontend/templates/forms.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/frontend/templates/forms.rs b/src/frontend/templates/forms.rs index 410dce0..a5c3ac4 100644 --- a/src/frontend/templates/forms.rs +++ b/src/frontend/templates/forms.rs @@ -42,9 +42,9 @@ impl Default for InputGroup<'_> { } impl InputGroup<'_> { - fn main_input(&self) -> Markup { + fn main_input(&self, force_required: bool) -> Markup { html! { - input .form-control #(self.name) name={ (self.name) } type={ (self.r#type) } required[self.required] disabled[self.disabled] value=[self.value.clone()]; + input .form-control #(self.name) name={ (self.name) } type={ (self.r#type) } required[self.required || force_required] disabled[self.disabled] value=[self.value.clone()]; } } } @@ -55,13 +55,13 @@ impl Render for InputGroup<'_> { .mb-3 { label .form-label for={ (self.name) } { (self.title) } @if self.required { - (self.main_input()) + (self.main_input(false)) } @else { .input-group { .input-group-text { input .form-check-input.mt-0.input-toggle type="checkbox" checked[!self.disabled]; } - (self.main_input()) + (self.main_input(true)) } } }