Move annotation of field validation failures to CSS

This commit is contained in:
Jeremy Stretch 2024-01-18 09:26:18 -05:00
parent 755da9fd73
commit 43a11ddce8
4 changed files with 17 additions and 23 deletions

Binary file not shown.

View File

@ -37,16 +37,6 @@ $spacing-s: $input-padding-x;
.ss-main {
color: $form-select-color;
&.is-invalid .ss-single-selected,
&.is-invalid .ss-multi-selected {
border-color: $form-feedback-icon-invalid-color;
}
&.is-valid .ss-single-selected,
&.is-valid .ss-multi-selected {
border-color: $form-feedback-icon-valid-color;
}
.ss-single-selected,
.ss-multi-selected {
padding: $form-select-padding-y $input-padding-x $form-select-padding-y $form-select-padding-x;
@ -195,3 +185,11 @@ $spacing-s: $input-padding-x;
}
}
}
// Apply red border for fields inside a row with .has-errors
.has-errors {
.ss-single-selected,
.ss-multi-selected {
border-color: $red;
}
}

View File

@ -16,3 +16,12 @@ form.object-edit {
content: '\f06C4';
}
}
// Set red border on form fields inside a row with .has-errors
.has-errors {
input,
select,
textarea {
border: 1px solid $red;
}
}

View File

@ -51,19 +51,6 @@ class BootstrapMixin:
# if 'placeholder' not in field.widget.attrs and field.label is not None:
# field.widget.attrs['placeholder'] = field.label
def is_valid(self):
is_valid = super().is_valid()
# Apply is-invalid CSS class to fields with errors
if not is_valid:
for field_name in self.errors:
# Ignore e.g. __all__
if field := self.fields.get(field_name):
css = field.widget.attrs.get('class', '')
field.widget.attrs['class'] = f'{css} is-invalid'
return is_valid
class CheckLastUpdatedMixin(forms.Form):
"""