From bfa2f0a64a551208f3317979d83920f644c4300e Mon Sep 17 00:00:00 2001 From: Thomas Gideon Date: Fri, 19 Jun 2020 16:35:43 -0400 Subject: [PATCH] Add validation styling --- Cargo.toml | 2 +- src/input/mod.rs | 12 +++++++++--- src/input/textarea.rs | 5 ++++- src/prelude/mod.rs | 8 ++++++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 02dcac4..ac4dccc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bootstrap-rs" -version = "0.2.3" +version = "0.2.4" authors = ["Thomas Gideon "] edition = "2018" diff --git a/src/input/mod.rs b/src/input/mod.rs index f5b0bf1..5b61929 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -55,6 +55,8 @@ pub struct Props { pub class: String, #[prop_or_default] pub style: String, + #[prop_or_default] + pub valid: Option, } impl Component for Input { @@ -84,11 +86,15 @@ impl Component for Input { } fn view(&self) -> Html { - let class = if self.props.readonly { - calculate_classes("form-control-plaintext", (&self.props).into()) + let prefix = if self.props.readonly { + format!( + "form-control-plaintext{}", + valid_as_class(&self.props.valid) + ) } else { - calculate_classes("form-control", (&self.props).into()) + format!("form-control{}", valid_as_class(&self.props.valid)) }; + let class = calculate_classes(prefix, (&self.props).into()); html! { , } impl Component for TextArea { @@ -65,11 +67,12 @@ impl Component for TextArea { } fn view(&self) -> Html { + let prefix = format!("form-control{}", valid_as_class(&self.props.valid)); html! {