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, r#type: forms::InputType::Text,
name: "name", name: "name",
title: "Name", title: "Name",
optional: true,
value: form.name.clone(), value: form.name.clone(),
..Default::default() ..Default::default()
}) })
@ -280,6 +281,7 @@ async fn add_form(
r#type: forms::InputType::Text, r#type: forms::InputType::Text,
name: "parent", name: "parent",
title: "Parent", title: "Parent",
optional: true,
value: form.parent.map(|id| id.to_string()), value: form.parent.map(|id| id.to_string()),
datalist: Some(&datalist_items), datalist: Some(&datalist_items),
..Default::default() ..Default::default()
@ -288,6 +290,7 @@ async fn add_form(
r#type: forms::InputType::Text, r#type: forms::InputType::Text,
name: "original_packaging", name: "original_packaging",
title: "Original Packaging", title: "Original Packaging",
optional: true,
disabled: true, disabled: true,
value: form.original_packaging.map(|id| id.to_string()), value: form.original_packaging.map(|id| id.to_string()),
datalist: Some(&datalist_items), datalist: Some(&datalist_items),
@ -364,6 +367,7 @@ async fn edit_form(
r#type: forms::InputType::Text, r#type: forms::InputType::Text,
name: "name", name: "name",
title: "Name", title: "Name",
optional: true,
disabled: item.name.is_none(), disabled: item.name.is_none(),
value: item.name, value: item.name,
..Default::default() ..Default::default()
@ -381,6 +385,7 @@ async fn edit_form(
r#type: forms::InputType::Text, r#type: forms::InputType::Text,
name: "parent", name: "parent",
title: "Parent", title: "Parent",
optional: true,
value: item.parent.map(|id| id.to_string()), value: item.parent.map(|id| id.to_string()),
disabled: item.parent.is_none(), disabled: item.parent.is_none(),
datalist: Some(&datalist_items), datalist: Some(&datalist_items),
@ -390,6 +395,7 @@ async fn edit_form(
r#type: forms::InputType::Text, r#type: forms::InputType::Text,
name: "original_packaging", name: "original_packaging",
title: "Original Packaging", title: "Original Packaging",
optional: true,
value: item.original_packaging.map(|id| id.to_string()), value: item.original_packaging.map(|id| id.to_string()),
disabled: item.original_packaging.is_none(), disabled: item.original_packaging.is_none(),
datalist: Some(&datalist_items), datalist: Some(&datalist_items),

View file

@ -227,6 +227,7 @@ async fn add_form(
r#type: forms::InputType::Text, r#type: forms::InputType::Text,
name: "parent", name: "parent",
title: "Parent", title: "Parent",
optional: true,
disabled: form.parent.is_none(), disabled: form.parent.is_none(),
value: form.parent.map(|id| id.to_string()), value: form.parent.map(|id| id.to_string()),
datalist: Some(&datalist_item_classes), datalist: Some(&datalist_item_classes),
@ -302,6 +303,7 @@ async fn edit_form(
r#type: forms::InputType::Text, r#type: forms::InputType::Text,
name: "parent", name: "parent",
title: "Parent", title: "Parent",
optional: true,
disabled: item_class.parent.is_none(), disabled: item_class.parent.is_none(),
value: item_class.parent.map(|id| id.to_string()), value: item_class.parent.map(|id| id.to_string()),
datalist: Some(&datalist_item_classes), datalist: Some(&datalist_item_classes),

View file

@ -26,6 +26,7 @@ pub struct InputGroup<'a> {
pub name: &'a str, pub name: &'a str,
pub title: &'a str, pub title: &'a str,
pub required: bool, pub required: bool,
pub optional: bool,
pub disabled: bool, pub disabled: bool,
pub value: Option<String>, pub value: Option<String>,
pub datalist: Option<&'a Datalist>, pub datalist: Option<&'a Datalist>,
@ -38,6 +39,7 @@ impl Default for InputGroup<'_> {
name: "placeholder", name: "placeholder",
title: "Placeholder", title: "Placeholder",
required: false, required: false,
optional: false,
disabled: false, disabled: false,
value: None, value: None,
datalist: None, datalist: None,
@ -66,7 +68,7 @@ impl Render for InputGroup<'_> {
html! { html! {
.mb-3 { .mb-3 {
label .form-label for={ (self.name) } { (self.title) } label .form-label for={ (self.name) } { (self.title) }
@if self.required { @if !self.optional {
(self.main_input(false)) (self.main_input(false))
} @else { } @else {
.input-group { .input-group {