Skip to content

input with error #1399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pgml-dashboard/src/components/inputs/text/input/input.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
div[data-controller="inputs-text-input"] {
--bs-danger: #{$peach-shade-100};

span.material-symbols-outlined {
margin-left: -40px;
color: #{$slate-shade-100};

&.is-invalid {
color: var(--bs-danger);
}
}

input.form-control {
Expand All @@ -12,4 +18,10 @@ div[data-controller="inputs-text-input"] {
label.form-label {
font-weight: #{$font-weight-normal};
}

p {
small {
color: var(--bs-danger);
}
}
}
7 changes: 7 additions & 0 deletions pgml-dashboard/src/components/inputs/text/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct Input {
autocomplete: bool,
value: String,
required: bool,
error: Option<String>,
}

impl Input {
Expand All @@ -38,6 +39,7 @@ impl Input {
autocomplete: false,
value: "".to_string(),
required: false,
error: None,
}
}

Expand Down Expand Up @@ -90,6 +92,11 @@ impl Input {
self.required = true;
self
}

pub fn error(mut self, error: Option<impl ToString>) -> Self {
self.error = error.map(|e| e.to_string());
self
}
}

component!(Input);
15 changes: 13 additions & 2 deletions pgml-dashboard/src/components/inputs/text/input/template.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<% let (input_classes, icon_classes) = if error.is_some() {
("form-control is-invalid", "material-symbols-outlined is-invalid")
} else {
("form-control", "material-symbols-outlined")
};
%>
<div data-controller="inputs-text-input">
<% if let Some(label) = label { %>
<label class="form-label" for="<%= id %>"><%+ label %></label>
Expand All @@ -8,7 +14,7 @@
id="<%= id %>"
type="<%= type_ %>"
name="<%= name %>"
class="form-control"
class="<%= input_classes %>"
placeholder="<%= placeholder %>"
data-action="<%= input_actions %>"
autocomplete="<%= autocomplete %>"
Expand All @@ -20,10 +26,15 @@

<% if let Some(icon) = icon { %>
<span
class="material-symbols-outlined"
class="<%= icon_classes %>"
data-action="<%= icon_actions %>">
<%= icon %>
</span>
<% } %>
</div>
<% if let Some(error) = error { %>
<p class="mt-1 mb-0">
<small><%= error %></small>
</p>
<% } %>
</div>
10 changes: 10 additions & 0 deletions pgml-dashboard/src/components/pages/demo/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@
.type_("text") %>
</div>

<div class="py-5">
<%+ Input::new()
.label("What is your name?".into())
.icon("person")
.placeholder("Enter your name")
.name("name")
.type_("text")
.error(Some("Your name is not valid.")) %>
</div>

<div class="py-5">
<%+ Search::new(SearchOptions {
name: "Model search".into(),
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy