Struct patternfly_yew::ValidationFormContext
source · pub struct ValidationFormContext { /* private fields */ }Implementations§
source§impl ValidationFormContext
impl ValidationFormContext
sourcepub fn new(callback: Callback<GroupValidationResult>, state: InputState) -> Self
pub fn new(callback: Callback<GroupValidationResult>, state: InputState) -> Self
Examples found in repository?
src/form/mod.rs (lines 205-208)
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
fn view(&self, ctx: &Context<Self>) -> Html {
let mut classes = Classes::from("pf-c-form");
classes.extend(ctx.props().horizontal.clone());
if ctx.props().limit_width {
classes.push("pf-m-limit-width");
}
let alert = &ctx.props().alert;
let validation_alert = Self::make_alert(
self.validation.state,
(
ctx.props()
.validation_warning_title
.as_deref()
.unwrap_or("The form contains fields with warnings."),
&html!(),
),
(
ctx.props()
.validation_error_title
.as_deref()
.unwrap_or("The form contains fields with errors."),
&html!(),
),
);
// reduce by severity
let alert = match (alert, &validation_alert) {
(None, None) => None,
(Some(alert), None) | (None, Some(alert)) => Some(alert),
(Some(props), Some(validation)) if validation.r#type > props.r#type => Some(validation),
(Some(props), Some(_)) => Some(props),
};
let validation_context = ValidationFormContext::new(
ctx.link().callback(Msg::GroupValidationChanged),
self.validation.state,
);
html! (
<ContextProvider<ValidationFormContext> context={validation_context} >
<form
novalidate=true
class={classes}
id={ctx.props().id.clone()}
action={ctx.props().action.clone()}
method={ctx.props().method.clone()}
>
if let Some(alert) = alert {
<div class="pf-c-form__alert">
<Alert
inline=true
r#type={alert.r#type}
title={alert.title.clone()}
>
{ alert.children.clone() }
</Alert>
</div>
} else {
<div style="display: none;"></div>
}
{ for ctx.props().children.iter() }
</form>
</ContextProvider<ValidationFormContext>>
)
}pub fn is_error(&self) -> bool
sourcepub fn push_state(&self, state: GroupValidationResult)
pub fn push_state(&self, state: GroupValidationResult)
Examples found in repository?
src/form/group.rs (line 239)
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg {
Self::Message::Validate(value) => {
let state = ctx.props().validator.run(value);
if self.state != state {
self.state = state;
ctx.props()
.onvalidated
.emit(self.state.clone().unwrap_or_default());
if let Some((validation_ctx, _)) = ctx
.link()
.context::<ValidationFormContext>(Callback::noop())
{
validation_ctx
.push_state(GroupValidationResult(self.id.clone(), self.state.clone()));
}
}
}
}
true
}sourcepub fn clear_state(&self, id: String)
pub fn clear_state(&self, id: String)
Trait Implementations§
source§impl Clone for ValidationFormContext
impl Clone for ValidationFormContext
source§fn clone(&self) -> ValidationFormContext
fn clone(&self) -> ValidationFormContext
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Default for ValidationFormContext
impl Default for ValidationFormContext
source§fn default() -> ValidationFormContext
fn default() -> ValidationFormContext
Returns the “default value” for a type. Read more
source§impl PartialEq<ValidationFormContext> for ValidationFormContext
impl PartialEq<ValidationFormContext> for ValidationFormContext
source§fn eq(&self, other: &ValidationFormContext) -> bool
fn eq(&self, other: &ValidationFormContext) -> bool
impl StructuralPartialEq for ValidationFormContext
Auto Trait Implementations§
impl !RefUnwindSafe for ValidationFormContext
impl !Send for ValidationFormContext
impl !Sync for ValidationFormContext
impl Unpin for ValidationFormContext
impl !UnwindSafe for ValidationFormContext
Blanket Implementations§
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
Convert
self to a value of a Properties struct.source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
Convert
self to a value of a Properties struct.