app: asterisk for mail attribute when creating a user

This commit is contained in:
josef
2025-12-24 22:53:17 +01:00
committed by GitHub
parent 469f35c12c
commit 62ae1d73fa
2 changed files with 15 additions and 3 deletions
+4
View File
@@ -304,11 +304,14 @@ impl Component for CreateUserForm {
} }
fn get_custom_attribute_input(attribute_schema: &Attribute) -> Html { fn get_custom_attribute_input(attribute_schema: &Attribute) -> Html {
let mail_is_required = attribute_schema.name.as_str() == "mail";
if attribute_schema.is_list { if attribute_schema.is_list {
html! { html! {
<ListAttributeInput <ListAttributeInput
name={attribute_schema.name.clone()} name={attribute_schema.name.clone()}
attribute_type={attribute_schema.attribute_type} attribute_type={attribute_schema.attribute_type}
required={mail_is_required}
/> />
} }
} else { } else {
@@ -316,6 +319,7 @@ fn get_custom_attribute_input(attribute_schema: &Attribute) -> Html {
<SingleAttributeInput <SingleAttributeInput
name={attribute_schema.name.clone()} name={attribute_schema.name.clone()}
attribute_type={attribute_schema.attribute_type} attribute_type={attribute_schema.attribute_type}
required={mail_is_required}
/> />
} }
} }
+11 -3
View File
@@ -45,6 +45,8 @@ fn attribute_input(props: &AttributeInputProps) -> Html {
#[derive(Properties, PartialEq)] #[derive(Properties, PartialEq)]
struct AttributeLabelProps { struct AttributeLabelProps {
pub name: String, pub name: String,
#[prop_or(false)]
pub required: bool,
} }
#[function_component(AttributeLabel)] #[function_component(AttributeLabel)]
fn attribute_label(props: &AttributeLabelProps) -> Html { fn attribute_label(props: &AttributeLabelProps) -> Html {
@@ -66,7 +68,9 @@ fn attribute_label(props: &AttributeLabelProps) -> Html {
<label for={props.name.clone()} <label for={props.name.clone()}
class="form-label col-4 col-form-label" class="form-label col-4 col-form-label"
> >
{props.name[0..1].to_uppercase() + &props.name[1..].replace('_', " ")}{":"} {props.name[0..1].to_uppercase() + &props.name[1..].replace('_', " ")}
{if props.required { html!{<span class="text-danger">{"*"}</span>} } else { html!{} }}
{":"}
<button <button
class="btn btn-sm btn-link" class="btn btn-sm btn-link"
type="button" type="button"
@@ -85,13 +89,15 @@ pub struct SingleAttributeInputProps {
pub(crate) attribute_type: AttributeType, pub(crate) attribute_type: AttributeType,
#[prop_or(None)] #[prop_or(None)]
pub value: Option<String>, pub value: Option<String>,
#[prop_or(false)]
pub required: bool,
} }
#[function_component(SingleAttributeInput)] #[function_component(SingleAttributeInput)]
pub fn single_attribute_input(props: &SingleAttributeInputProps) -> Html { pub fn single_attribute_input(props: &SingleAttributeInputProps) -> Html {
html! { html! {
<div class="row mb-3"> <div class="row mb-3">
<AttributeLabel name={props.name.clone()} /> <AttributeLabel name={props.name.clone()} required={props.required} />
<div class="col-8"> <div class="col-8">
<AttributeInput <AttributeInput
attribute_type={props.attribute_type} attribute_type={props.attribute_type}
@@ -108,6 +114,8 @@ pub struct ListAttributeInputProps {
pub(crate) attribute_type: AttributeType, pub(crate) attribute_type: AttributeType,
#[prop_or(vec!())] #[prop_or(vec!())]
pub values: Vec<String>, pub values: Vec<String>,
#[prop_or(false)]
pub required: bool,
} }
pub enum ListAttributeInputMsg { pub enum ListAttributeInputMsg {
@@ -160,7 +168,7 @@ impl Component for ListAttributeInput {
let link = &ctx.link(); let link = &ctx.link();
html! { html! {
<div class="row mb-3"> <div class="row mb-3">
<AttributeLabel name={props.name.clone()} /> <AttributeLabel name={props.name.clone()} required={props.required} />
<div class="col-8"> <div class="col-8">
{self.indices.iter().map(|&i| html! { {self.indices.iter().map(|&i| html! {
<div class="input-group mb-2" key={i}> <div class="input-group mb-2" key={i}>