From 0db2acf4087a2769d806205365548a8dfdaf2de8 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sun, 14 Jul 2024 14:47:26 +0200 Subject: [PATCH] Allow InputGroup to be non-required --- src/frontend/item.rs | 6 ++++++ src/frontend/item_class.rs | 2 ++ src/frontend/templates/forms.rs | 4 +++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/frontend/item.rs b/src/frontend/item.rs index 075f5ec..88ab5b5 100644 --- a/src/frontend/item.rs +++ b/src/frontend/item.rs @@ -264,6 +264,7 @@ async fn add_form( r#type: forms::InputType::Text, name: "name", title: "Name", + optional: true, value: form.name.clone(), ..Default::default() }) @@ -280,6 +281,7 @@ async fn add_form( r#type: forms::InputType::Text, name: "parent", title: "Parent", + optional: true, value: form.parent.map(|id| id.to_string()), datalist: Some(&datalist_items), ..Default::default() @@ -288,6 +290,7 @@ async fn add_form( r#type: forms::InputType::Text, name: "original_packaging", title: "Original Packaging", + optional: true, disabled: true, value: form.original_packaging.map(|id| id.to_string()), datalist: Some(&datalist_items), @@ -364,6 +367,7 @@ async fn edit_form( r#type: forms::InputType::Text, name: "name", title: "Name", + optional: true, disabled: item.name.is_none(), value: item.name, ..Default::default() @@ -381,6 +385,7 @@ async fn edit_form( r#type: forms::InputType::Text, name: "parent", title: "Parent", + optional: true, value: item.parent.map(|id| id.to_string()), disabled: item.parent.is_none(), datalist: Some(&datalist_items), @@ -390,6 +395,7 @@ async fn edit_form( r#type: forms::InputType::Text, name: "original_packaging", title: "Original Packaging", + optional: true, value: item.original_packaging.map(|id| id.to_string()), disabled: item.original_packaging.is_none(), datalist: Some(&datalist_items), diff --git a/src/frontend/item_class.rs b/src/frontend/item_class.rs index 646fd0b..ccebba1 100644 --- a/src/frontend/item_class.rs +++ b/src/frontend/item_class.rs @@ -227,6 +227,7 @@ async fn add_form( r#type: forms::InputType::Text, name: "parent", title: "Parent", + optional: true, disabled: form.parent.is_none(), value: form.parent.map(|id| id.to_string()), datalist: Some(&datalist_item_classes), @@ -302,6 +303,7 @@ async fn edit_form( r#type: forms::InputType::Text, name: "parent", title: "Parent", + optional: true, disabled: item_class.parent.is_none(), value: item_class.parent.map(|id| id.to_string()), datalist: Some(&datalist_item_classes), diff --git a/src/frontend/templates/forms.rs b/src/frontend/templates/forms.rs index 2e3d76f..62706c4 100644 --- a/src/frontend/templates/forms.rs +++ b/src/frontend/templates/forms.rs @@ -26,6 +26,7 @@ pub struct InputGroup<'a> { pub name: &'a str, pub title: &'a str, pub required: bool, + pub optional: bool, pub disabled: bool, pub value: Option, pub datalist: Option<&'a Datalist>, @@ -38,6 +39,7 @@ impl Default for InputGroup<'_> { name: "placeholder", title: "Placeholder", required: false, + optional: false, disabled: false, value: None, datalist: None, @@ -66,7 +68,7 @@ impl Render for InputGroup<'_> { html! { .mb-3 { label .form-label for={ (self.name) } { (self.title) } - @if self.required { + @if !self.optional { (self.main_input(false)) } @else { .input-group {