Allow InputGroup to be non-required

This commit is contained in:
Simon Bruder 2024-07-14 14:47:26 +02:00
parent 8ddde10e37
commit 0db2acf408
Signed by: simon
GPG key ID: 347FF8699CDA0776
3 changed files with 11 additions and 1 deletions

View file

@ -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),

View file

@ -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),

View file

@ -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<String>,
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 {