-
Notifications
You must be signed in to change notification settings - Fork 81
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
Bootstrap 4 and Bootstrap 5 validation #42
Comments
Here is mixin of form state that should be used to change style: There are different other things to consider if changing style to cover this. |
I make here a PR: #43 I just add success/error class to input, by keeping the same on parent. |
@thewebartisan7, I think there's an easier way to solve this problem. error & success classes are added to the element you specify in |
Ah, let me try. I think that we can fix findAncestor like this: export function findAncestor (el, cls) {
// Check before in current el before check in parent
if(!el.classList.contains(cls))
while ((el = el.parentElement) && !el.classList.contains(cls));
return el;
} This was first thing that I looks into, but didn't test. I will check now. Anyway, I notice that when I install via NPM is not the actual version that I see here in github, for example is missing equals and some other change. |
Nope, this doesn't work. Almost not how I change findAncestor. First the errors is not added, only input receive class is-invalid. But another error is that checkbox or radio input has not Then is not found by findAncestor and appear error: TypeError: errorClassElement is null |
checkbox or radio input not having Errors are added based on I'll create a codepen and check in detail. If you already have something, please share it with me. |
I think I got the issue:
needs to be changed to:
I'll check if there's any side effects and make the change. The solution you proposed may have side effects because of adding the same class to parent and child. That's why I'm looking for a different approach. |
Yes this can be a solution also to fix issue that happen right now where also fields that doesn't require validation, example a not required input, receive a is-valid class, then become green. But I don't like really the idea to add new class to input...
I understand what you mean, but if you think about, usually a parent invalid class check child, like I don't see how can impact on style since is never used alone. Better this than adding custom classes to input. Looking for your update. Thanks |
Maybe add new options, like |
+1 A |
+1 Any ETA for this fix, @sha256 ? |
Also wondering if an update is coming for this |
any updates regarding this? |
I have found a workaround! /* PristineJS Bootstrap Fix */
.input-group.is-invalid > input.form-control,
.form-group.is-invalid > input.form-control {
border-color: #dc3545;
padding-right: 2.25rem !important;
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23dc3545' viewBox='0 0 12 12'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
background-repeat: no-repeat;
background-position: right calc(0.375em + 0.1875rem) center;
background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}
.input-group.is-valid > input.form-control,
.form-group.is-valid > input.form-control {
border-color: #28a745;
padding-right: 2.25rem !important;
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3e%3cpath fill='%2328a745' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e");
background-repeat: no-repeat;
background-position: right calc(0.375em + 0.1875rem) center;
background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
} |
still waiting for classToSelf everything else conflicts with other parts of my app. |
I would like to use bootstrap 4 and bootstrap 5 default validation classes, but seem not possible.
For display
.invalid-feedback
the input must have.is-invalid
or.valid-feedback
with.is-valid
, example:If I change the default class name like so:
The errors is not visible because class
.is-invalid
is not added to input but to form-group, example:I could solve this by adding extra CSS like
.is-invalid .invalid-feedback {display: block}
(not completely because need also to consider input group border, dark theme of bootstrap 5, etc). Would be good to have a way to do this without extra CSS, if possible without breaking change.Bootstrap has also a class .was-validated, that show invalid feedback depending on HTML5 validation, like
.was-validated :invalid ~ .invalid-feedback {display: block}
But this doesn't work for example with input type email where HTML5 consider valid
email@example
while pristine correctly mark this as invalid.The text was updated successfully, but these errors were encountered: