diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index ed2f8085a32..3a6cff28efc 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -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.