Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog_Dyva.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Backported from Dolibarr:
- Backport develop commit b9967552a9fa38c8fd6aef2fbd113100259bf851 : JS validation
- Backport develop PR #33696 : new conf to remove break before country in pdf
28 changes: 14 additions & 14 deletions htdocs/core/lib/functions.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -11133,21 +11133,20 @@ function printCommonFooter($zone = 'private')

foreach ($defval as $paramkey => $paramval) {
// Solution 1: Add handler on submit to check if mandatory fields are empty
print 'var form = $(\'#'.dol_escape_js($paramkey).'\').closest("form");'."\n";
print 'var form = $(\'[name="'.dol_escape_js($paramkey).'"]\').closest("form");'."\n";
print "form.on('submit', function(event) {
var submitter = $(this).find(':submit:focus').get(0);
if (submitter) {
var buttonName = $(submitter).attr('name');
if (buttonName == 'cancel') {
console.log('We click on cancel button so we accept submit with no need to check mandatory fields');
return true;
}
var submitter = \$(this).find(':submit:focus').get(0);
var buttonName = submitter ? \$(submitter).attr('name') : 'save';

if (buttonName == 'cancel') {
console.log('We click on cancel button so we accept submit with no need to check mandatory fields');
return true;
}

console.log('We did not click on cancel button but on something else, we check that field #".dol_escape_js($paramkey)." is not empty');
console.log('We did not click on cancel button but on something else, we check that field [name=".dol_escape_js($paramkey)."] is not empty');

var tmpvalue = jQuery('#".dol_escape_js($paramkey)."').val();
let tmptypefield = jQuery('#".dol_escape_js($paramkey)."').prop('nodeName').toLowerCase(); // Get the tag name (div, section, footer...)
var tmpvalue = jQuery('[name=\"".dol_escape_js($paramkey)."\"]').val();
let tmptypefield = jQuery('[name=\"".dol_escape_js($paramkey)."\"]').prop('nodeName').toLowerCase(); // Get the tag name (div, section, footer...)

if (tmptypefield == 'textarea') {
// We must instead check the content of ckeditor
Expand All @@ -11165,11 +11164,13 @@ function printCommonFooter($zone = 'private')
if (tmpvalue === '0' && (tmptypefield == 'select' || tmptypefield == 'input')) {
tmpvalueisempty = true;
}
if (tmpvalueisempty && (buttonName == 'save')) {
if (tmpvalueisempty && buttonName !== 'cancel') {
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.
alert('".dol_escape_js($langs->trans("ErrorFieldRequired", $paramkey).' ('.$langs->trans("CustomMandatoryFieldRule").')')."');

alert('".dol_escape_js($langs->transnoentitiesnoconv("ErrorFieldRequired", $paramkey).' ('.$langs->transnoentitiesnoconv("CustomMandatoryFieldRule").')')."');

return false;
}
console.log('field has type '+tmptypefield+' and is defined to '+tmpvalue);
Expand All @@ -11193,7 +11194,6 @@ function printCommonFooter($zone = 'private')
print 'jQuery(\':input[name="' . dol_escape_js($paramkey) . '"]\').closest("tr").find("td:first").addClass("fieldrequired");'."\n";
}


// If we submit using the cancel button, we remove the required attributes
print 'jQuery("input[name=\'cancel\']").click(function() {
console.log("We click on cancel button so removed all required attribute");
Expand Down
Loading