Skip to content

Instantly share code, notes, and snippets.

@Summonshr
Last active October 30, 2023 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Summonshr/aa64363d4fa019921ca0ad01821a35f3 to your computer and use it in GitHub Desktop.
Save Summonshr/aa64363d4fa019921ca0ad01821a35f3 to your computer and use it in GitHub Desktop.
Laravel nova: hide error when input change
<?php
// Inside boot method
Nova::serving(function () {
Nova::script('input-error-handler-js', public_path('custom/js/nova.js'));
Nova::style('input-error-handler-css', public_path('custom/css/nova.css'));
});
(function () {
var origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function () {
this.addEventListener('load', function () {
if (this.status === 422) {
var elements = document.querySelectorAll('.custom-error-hidden');
elements.forEach(function (element) {
if (element.classList.contains('custom-error-hidden')) {
element.classList.remove('custom-error-hidden');
}
});
}
});
origOpen.apply(this, arguments);
};
})();
document.querySelector('#app').addEventListener('input', function (event) {
if (event.target.classList.contains('form-input-bordered') || event.target.classList.contains('form-select-bordered')) {
event.target.parentElement.parentElement.parentElement.classList.add('custom-error-hidden')
}
});
.custom-error-hidden .help-text-error {
display: none;
}
#nova .custom-error-hidden .form-input-border-error {
border-color: rgba(var(--colors-gray-700)) !important;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment