remove validate_input widget

This commit is contained in:
Piotr 2024-05-17 00:55:53 +02:00
parent 624989d039
commit ad8f1a43cc
2 changed files with 8 additions and 24 deletions

View file

@ -1,8 +1,7 @@
use cosmic::app::{Application, Command, Core, Settings};
use cosmic::iced;
use cosmic::iced::executor;
use cosmic::iced_core::Size;
use cosmic::widget::{column, text_input, validate_input};
use cosmic::widget::{column, text_input};
use cosmic::Element;
use regex::Regex;
@ -43,10 +42,7 @@ impl Application for Window {
)
}
fn update(
&mut self,
message: Self::Message,
) -> iced::Command<cosmic::app::Message<Self::Message>> {
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
match message {
Message::InputName(name) => self.name = name,
Message::InputEmail(email) => self.email = email,
@ -59,7 +55,8 @@ impl Application for Window {
let validation_condition = emailregex.is_match(&self.email);
let name_input = text_input("Name", &self.name).on_input(Message::InputName);
let email_input = validate_input("E-mail", &self.email, validation_condition)
let email_input = text_input("E-mail", &self.email)
.validation_condition(validation_condition)
.on_input(Message::InputEmail);
column()

View file

@ -160,20 +160,6 @@ where
.padding([spacing, spacing, spacing, spacing])
}
/// Creates a new validate input [`TextInput`].
///
/// [`TextInput`]: widget::TextInput
pub fn validate_input<'a, Message>(
placeholder: impl Into<Cow<'a, str>>,
value: impl Into<Cow<'a, str>>,
validate_condition: bool,
) -> TextInput<'a, Message>
where
Message: Clone + 'static,
{
TextInput::new(placeholder, value).validation_condition(validate_condition)
}
#[cfg(feature = "wayland")]
pub(crate) const SUPPORTED_TEXT_MIME_TYPES: &[&str; 6] = &[
"text/plain;charset=utf-8",
@ -314,7 +300,7 @@ where
self
}
fn validation_condition(mut self, validation_condition: bool) -> Self {
pub fn validation_condition(mut self, validation_condition: bool) -> Self {
self.is_validated = Some(validation_condition);
self
}
@ -2054,8 +2040,9 @@ pub fn draw<'a, Message>(
}
if is_validated.is_some() {
if !is_validated.unwrap() {
border_color = Color::from_rgb(0.95, 0.30, 0.30);
if !is_validated.unwrap_or_default() {
border_color =
Color::from(palette::Srgb::new(0.890, 0.145, 0.420));
}
}