37 lines
971 B
Rust
37 lines
971 B
Rust
use leptos::*;
|
|||
|
|
use crate::locales::trl;
|
||
|
|
use crate::validator::Validator;
|
||
|
|
|
||
|
|
#[component]
|
||
|
|
pub fn ValidationErr(
|
||
|
|
cx: Scope,
|
||
|
|
validator: Validator,
|
||
|
|
) -> impl IntoView {
|
||
|
|
view! {cx, {move || {
|
||
|
|
if !validator.is_valid() {
|
||
|
|
if let Some(msgs) = validator.messages() {
|
||
|
|
let out_msgs = msgs.into_iter().map(move |e| {
|
||
|
|
view! {cx,
|
||
|
|
<div class="alert alert-danger">
|
||
|
|
{trl(cx, &e)}
|
||
|
|
</div>
|
||
|
|
}
|
||
|
|
}).collect_view(cx);
|
||
|
|
view! {cx,
|
||
|
|
<div>
|
||
|
|
{out_msgs}
|
||
|
|
</div>
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
view! {cx,
|
||
|
|
<div class="alert alert-danger">
|
||
|
|
"Validation error"
|
||
|
|
</div>
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
view! {cx, <div></div>}
|
||
|
|
}
|
||
|
|
}}
|
||
|
|
}
|
||
|
|
}
|