Merge pull request #32766 from PsyCrow-code/patch-1

FIX #32765 JS Error: Uncaught TypeError
This commit is contained in:
Laurent Destailleur 2025-01-24 10:27:01 +01:00 committed by GitHub
commit 5568734d1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11036,7 +11036,7 @@ function printCommonFooter($zone = 'private')
}
// Management of focus and mandatory for fields
if ($action == 'create' || $action == 'edit' || (empty($action) && (preg_match('/new\.php/', $_SERVER["PHP_SELF"]))) || ((empty($action) || $action == 'addline') && (preg_match('/card\.php/', $_SERVER["PHP_SELF"])))) {
if ($action == 'create' || $action == 'add' || $action == 'edit' || (empty($action) && (preg_match('/new\.php/', $_SERVER["PHP_SELF"]))) || ((empty($action) || $action == 'addline') && (preg_match('/card\.php/', $_SERVER["PHP_SELF"])))) {
print '/* JS CODE TO ENABLE to manage focus and mandatory form fields */'."\n";
$relativepathstring = $_SERVER["PHP_SELF"];
// Clean $relativepathstring
@ -11107,7 +11107,7 @@ function printCommonFooter($zone = 'private')
// Solution 1: Add handler on submit to check if mandatory fields are empty
print 'var form = $(\'#'.dol_escape_js($paramkey).'\').closest("form");'."\n";
print "form.on('submit', function(event) {
var submitter = event.originalEvent.submitter;
var submitter = $(this).find(':submit:focus').get(0);
if (submitter) {
var buttonName = $(submitter).attr('name');
if (buttonName == 'cancel') {
@ -11134,10 +11134,10 @@ function printCommonFooter($zone = 'private')
if (tmpvalue === null || tmpvalue === undefined || tmpvalue === '') {
tmpvalueisempty = true;
}
if (tmpvalue === '0' && tmptypefield == 'select') {
if (tmpvalue === '0' && (tmptypefield == 'select' || tmptypefield == 'input')) {
tmpvalueisempty = true;
}
if (tmpvalueisempty) {
if (tmpvalueisempty && (buttonName == 'save')) {
console.log('field has type '+tmptypefield+' and is empty, we cancel the submit');
event.preventDefault(); // Stop submission of form to allow custom code to decide.
event.stopPropagation(); // Stop other handlers.