|
|
|
@ -66,6 +66,7 @@ impl Component for Input {
|
|
|
|
|
render_if_ne(&mut self.props, props) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[cfg(not(feature = "validate"))] |
|
|
|
|
fn view(&self) -> Html { |
|
|
|
|
let input_type = self.props.input_type.as_ref().unwrap_or(&InputType::Text); |
|
|
|
|
let mut prefix = if self.props.readonly { |
|
|
|
@ -84,11 +85,40 @@ impl Component for Input {
|
|
|
|
|
}; |
|
|
|
|
render::render_with_prefix(&self.props, prefix, html) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[cfg(feature = "validate")] |
|
|
|
|
fn view(&self) -> Html { |
|
|
|
|
let input_type = self.props.input_type.as_ref().unwrap_or(&InputType::Text); |
|
|
|
|
let mut prefix = if self.props.readonly { |
|
|
|
|
vec!["form-control-plaintext"] |
|
|
|
|
} else { |
|
|
|
|
vec!["form-control"] |
|
|
|
|
}; |
|
|
|
|
prefix.push(valid_as_class(&self.props.valid)); |
|
|
|
|
let html = html! { |
|
|
|
|
<> |
|
|
|
|
<input |
|
|
|
|
type=input_type |
|
|
|
|
value=&self.state |
|
|
|
|
readonly=self.props.readonly |
|
|
|
|
onchange=self.link.callback(|evt| InputChange(evt)) |
|
|
|
|
/> |
|
|
|
|
{ crate::input::render_validation_feedback_from_props(&self.props) } |
|
|
|
|
</> |
|
|
|
|
}; |
|
|
|
|
render::render_with_prefix(&self.props, prefix, html) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[cfg(feature = "validate")] |
|
|
|
|
fn render_validation_feedback<S: AsRef<str>>(field: S, errors: &Option<ValidationErrors>) -> Html { |
|
|
|
|
if let Some(ref errors) = errors { |
|
|
|
|
pub fn render_validation_feedback( |
|
|
|
|
error_key: &Option<String>, |
|
|
|
|
errors: &Option<ValidationErrors>, |
|
|
|
|
) -> Html { |
|
|
|
|
// TODO keep chipping away
|
|
|
|
|
if error_key.is_none { |
|
|
|
|
html! {} |
|
|
|
|
} else if let Some(ref errors) = errors { |
|
|
|
|
let errors = errors.field_errors(); |
|
|
|
|
if let Some(errors) = errors.get(field.as_ref()) { |
|
|
|
|
html! { |
|
|
|
@ -103,3 +133,12 @@ fn render_validation_feedback<S: AsRef<str>>(field: S, errors: &Option<Validatio
|
|
|
|
|
html! {} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[cfg(feature = "validate")] |
|
|
|
|
fn render_validation_feedback_from_props(props: &Props) -> Html { |
|
|
|
|
if let Some(error_code) = props.error_code.as_ref() { |
|
|
|
|
render_validation_feedback(error_code, &props.errors) |
|
|
|
|
} else { |
|
|
|
|
html! {} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|