Last active
October 30, 2023 08:54
-
-
Save Summonshr/aa64363d4fa019921ca0ad01821a35f3 to your computer and use it in GitHub Desktop.
Laravel nova: hide error when input change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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')); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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') | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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