You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On below registration form the form validation, which is the tick does not show when the user uses the browser saved data, but shows up the when user enter the data manually. Below images show for reference,
When manually entered,
When used the browser saved data,
Please refer the below code
<!doctype html><htmllang="en"><head><!-- Required meta tags and Bootstrap CSS --><metacharset="utf-8"><metaname="viewport" content="width=device-width, initial-scale=1"><title>Registration Form</title><!-- Bootstrap CSS --><linkhref="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><style>
/* Optional: Adjust form width on larger screens */
.registration-form {
max-width: 500px;
margin: auto;
}
/* Remove autofill background color in Chrome */
input:-webkit-autofill {
-webkit-box-shadow: 0 0 0 1000px white inset !important; /* Changes background to white */
-webkit-text-fill-color: #000 !important; /* Ensures text remains black */
}
</style></head><body><divclass="container mt-5"><divclass="registration-form"><divclass="card"><divclass="card-body"><h3class="card-title text-center mb-4">Register</h3><formclass="needs-validation" novalidate><!-- First Name and Last Name --><divclass="row"><divclass="col-md-6 mb-3"><labelfor="firstName" class="form-label">First Name</label><inputtype="text" class="form-control" id="firstName" pattern="^[A-Za-z]+$" placeholder="First Name" required><divclass="invalid-feedback">
Please enter your first name (letters only).
</div></div><divclass="col-md-6 mb-3"><labelfor="lastName" class="form-label">Last Name</label><inputtype="text" class="form-control" id="lastName" pattern="^[A-Za-z]+$" placeholder="Last Name" required><divclass="invalid-feedback">
Please enter your last name (letters only).
</div></div></div><!-- Email --><divclass="mb-3"><labelfor="emailAddress" class="form-label">Email</label><inputtype="email" class="form-control" id="emailAddress" placeholder="Email" required><divclass="invalid-feedback">
Please enter a valid email address.
</div></div><!-- Password --><divclass="mb-3"><labelfor="password" class="form-label">Password</label><inputtype="password" class="form-control" id="password" minlength="6" placeholder="Password" required><divclass="invalid-feedback">
Please enter a password with at least 6 characters.
</div></div><!-- Confirm Password --><divclass="mb-3"><labelfor="confirmPassword" class="form-label">Confirm Password</label><inputtype="password" class="form-control" id="confirmPassword" minlength="6" placeholder="Confirm Password" required><divclass="invalid-feedback">
Passwords do not match.
</div></div><!-- Terms and Conditions --><divclass="form-check mb-3"><inputtype="checkbox" id="terms" class="form-check-input" required><labelclass="form-check-label" for="terms">I agree to the terms and conditions</label><divclass="invalid-feedback">
You must agree to the terms and conditions.
</div></div><!-- Submit Button --><divclass="d-grid"><buttonclass="btn btn-primary" type="submit">Register</button></div></form></div></div></div></div><!-- Bootstrap JS and custom validation script --><scriptsrc="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script><script>(()=>{'use strict';// Fetch all the forms we want to apply custom Bootstrap validation styles toconstforms=document.querySelectorAll('.needs-validation');// Trigger validation for autofilled fields on page loadconsttriggerAutofillValidation=()=>{constautofillFields=document.querySelectorAll('input:-webkit-autofill');// Dispatch an input event for each autofilled field to trigger validationautofillFields.forEach(field=>{field.dispatchEvent(newEvent('input',{bubbles: true}));});};// On window load, trigger autofill validationwindow.addEventListener('load',triggerAutofillValidation);// Loop over each form and prevent submission if invalidArray.from(forms).forEach(form=>{// Password and Confirm Password fieldsconstpassword=form.querySelector('#password');constconfirmPassword=form.querySelector('#confirmPassword');// Event listener to validate password matchconfirmPassword.addEventListener('input',function(){if(confirmPassword.value!==password.value){confirmPassword.setCustomValidity('Passwords do not match');}else{confirmPassword.setCustomValidity('');}});// Form submission eventform.addEventListener('submit',event=>{// Check for validityif(!form.checkValidity()){event.preventDefault();event.stopPropagation();}// Add Bootstrap validation classesform.classList.add('was-validated');},false);});})();</script></body></html>
Reduced test cases
None
What operating system(s) are you seeing the problem on?
Windows
What browser(s) are you seeing the problem on?
Chrome, Microsoft Edge
What version of Bootstrap are you using?
v5.3.3
The text was updated successfully, but these errors were encountered:
The issue is that the user agent stylesheet sets the background-image to none!important, making them non-overridable which means our background image won’t show when users select saved data. According to the MDN documentation, we can’t easily change this. You can check out: MDN :autofill
However, we can use, for example, the trickbox-shadow: 0 0 0 1000px orangered inset; to customize the background color, but this is not our main goal since we want to show the tick image.
Prerequisites
Describe the issue
On below registration form the form validation, which is the tick does not show when the user uses the browser saved data, but shows up the when user enter the data manually. Below images show for reference,
When manually entered,
When used the browser saved data,
Please refer the below code
Reduced test cases
None
What operating system(s) are you seeing the problem on?
Windows
What browser(s) are you seeing the problem on?
Chrome, Microsoft Edge
What version of Bootstrap are you using?
v5.3.3
The text was updated successfully, but these errors were encountered: