Form constraints validation

This commit is contained in:
teapotd 2020-04-01 11:08:02 +02:00
parent e47e884cc7
commit 779552ee7d
72 changed files with 1224 additions and 4336 deletions

View file

@ -184,6 +184,9 @@ pub struct TextInput<T: ClipboardProvider> {
/// <https://html.spec.whatwg.org/multipage/#attr-fe-maxlength>
max_length: Option<UTF16CodeUnits>,
min_length: Option<UTF16CodeUnits>,
/// Was last change made by set_content?
was_last_change_by_set_content: bool,
}
/// Resulting action to be taken by the owner of a text input that is handling an event.
@ -269,6 +272,7 @@ impl<T: ClipboardProvider> TextInput<T> {
max_length: max_length,
min_length: min_length,
selection_direction: selection_direction,
was_last_change_by_set_content: true,
};
i.set_content(initial);
i
@ -300,6 +304,11 @@ impl<T: ClipboardProvider> TextInput<T> {
self.min_length = length;
}
/// Was last edit made by set_content?
pub fn was_last_change_by_set_content(&self) -> bool {
self.was_last_change_by_set_content
}
/// Remove a character at the current editing point
pub fn delete_char(&mut self, dir: Direction) {
if self.selection_origin.is_none() || self.selection_origin == Some(self.edit_point) {
@ -496,6 +505,7 @@ impl<T: ClipboardProvider> TextInput<T> {
};
self.lines = new_lines;
self.was_last_change_by_set_content = false;
self.clear_selection();
self.assert_ok_selection();
}
@ -1035,6 +1045,7 @@ impl<T: ClipboardProvider> TextInput<T> {
vec![content]
};
self.was_last_change_by_set_content = true;
self.edit_point = self.edit_point.constrain_to(&self.lines);
if let Some(origin) = self.selection_origin {