🚧 Simplifica preparación opcional
This commit is contained in:
parent
297d1fc338
commit
f87b236659
2 changed files with 5 additions and 13 deletions
|
|
@ -71,9 +71,11 @@ impl ComponentTrait for Input {
|
|||
InputType::Url => "url",
|
||||
};
|
||||
let id = self.name().get().map(|name| concat_string!("edit-", name));
|
||||
let label = self.label().prepare(rcx);
|
||||
let description = self.help_text().prepare(rcx);
|
||||
PrepareMarkup::With(html! {
|
||||
div class=[self.classes().get()] {
|
||||
@if let Some(label) = self.label().prepare_optional(rcx) {
|
||||
@if !label.is_empty() {
|
||||
label class="form-label" for=[&id] {
|
||||
(label) " "
|
||||
@if self.required().get().is_some() {
|
||||
|
|
@ -98,7 +100,7 @@ impl ComponentTrait for Input {
|
|||
readonly=[self.readonly().get()]
|
||||
required=[self.required().get()]
|
||||
disabled=[self.disabled().get()];
|
||||
@if let Some(description) = self.help_text().prepare_optional(rcx) {
|
||||
@if !description.is_empty() {
|
||||
div class="form-text" { (description) }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ impl<T: ComponentTrait + Default> OneComponent<T> {
|
|||
self.0 = Some(Arc::new(RwLock::new(component)));
|
||||
}
|
||||
|
||||
// OneComponent RENDER.
|
||||
// OneComponent PREPARE.
|
||||
|
||||
pub fn prepare(&self, rcx: &mut RenderContext) -> Markup {
|
||||
if let Some(component) = &self.0 {
|
||||
|
|
@ -27,14 +27,4 @@ impl<T: ComponentTrait + Default> OneComponent<T> {
|
|||
}
|
||||
html! {}
|
||||
}
|
||||
|
||||
pub fn prepare_optional(&self, rcx: &mut RenderContext) -> Option<Markup> {
|
||||
if let Some(component) = &self.0 {
|
||||
let render = component.write().unwrap().prepare(rcx).into_string();
|
||||
if !render.trim().is_empty() {
|
||||
return Some(html! { (render) });
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue