diff --git a/htdocs/admin/defaultvalues.php b/htdocs/admin/defaultvalues.php index 2e4d25ae29459..4d75ab4423548 100644 --- a/htdocs/admin/defaultvalues.php +++ b/htdocs/admin/defaultvalues.php @@ -235,13 +235,9 @@ { print info_admin($langs->trans("WarningSettingSortOrder")).'
'; } -if ($mode == 'focus') -{ - print info_admin($langs->trans("FeatureNotYetAvailable")).'
'; -} if ($mode == 'mandatory') { - print info_admin($langs->trans("FeatureNotYetAvailable")).'
'; + print info_admin($langs->trans("FeatureSupportedOnTextFieldsOnly")).'
'; } print ''; @@ -303,11 +299,11 @@ print ''; // Page print ''; -print ''; +print ''; print ''."\n"; // Field print ''; -print ''; +print ''; print ''; // Value if ($mode != 'focus' && $mode != 'mandatory') @@ -320,7 +316,7 @@ if (! empty($conf->multicompany->enabled) && !$user->entity) { print ''; - print ''; + print ''; // We see environment, but to change it we must switch on other entity print ''; } else diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 22291c6b4d882..36c7b2a58e192 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7023,7 +7023,8 @@ function complete_head_from_modules($conf,$langs,$object,&$head,&$h,$type,$mode= */ function printCommonFooter($zone='private') { - global $conf, $hookmanager; + global $conf, $hookmanager, $user; + global $action; global $micro_start_time; if ($zone == 'private') print "\n".''."\n"; @@ -7056,7 +7057,71 @@ function printCommonFooter($zone='private') print '});'."\n"; } - // Google Analytics (need Google module) + // Management of focus and mandatory for fields + if ($action == 'create' || $action == 'edit') + { + print '/* Code js to manage focus and mandatory form fields */'."\n"; + $relativepathstring = $_SERVER["PHP_SELF"]; + // Clean $relativepathstring + if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring); + $relativepathstring = preg_replace('/^\//', '', $relativepathstring); + $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring); + $tmpqueryarraywehave=explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING'])); + foreach($user->default_values[$relativepathstring]['focus'] as $defkey => $defval) + { + $qualified = 0; + if ($defkey != '_noquery_') + { + $tmpqueryarraytohave=explode('&', $defkey); + $foundintru=0; + foreach($tmpqueryarraytohave as $tmpquerytohave) + { + if (! in_array($tmpquerytohave, $tmpqueryarraywehave)) $foundintru=1; + } + if (! $foundintru) $qualified=1; + //var_dump($defkey.'-'.$qualified); + } + else $qualified = 1; + + if ($qualified) + { + foreach($defval as $paramkey => $paramval) + { + // Add property 'required' on input + print 'jQuery("input[name=\''.$paramkey.'\']").focus();'."\n"; + } + } + } + foreach($user->default_values[$relativepathstring]['mandatory'] as $defkey => $defval) + { + $qualified = 0; + if ($defkey != '_noquery_') + { + $tmpqueryarraytohave=explode('&', $defkey); + $foundintru=0; + foreach($tmpqueryarraytohave as $tmpquerytohave) + { + if (! in_array($tmpquerytohave, $tmpqueryarraywehave)) $foundintru=1; + } + if (! $foundintru) $qualified=1; + //var_dump($defkey.'-'.$qualified); + } + else $qualified = 1; + + if ($qualified) + { + foreach($defval as $paramkey => $paramval) + { + // Add property 'required' on input + print 'jQuery("input[name=\''.$paramkey.'\']").prop(\'required\',true);'."\n"; + print 'jQuery("select[name=\''.$paramkey.'\']").prop(\'required\',true);'."\n"; // required on a select works only if key is "", this does not happen in Dolibarr + } + } + } + } + + // Google Analytics + // TODO Add a hook here if (! empty($conf->google->enabled) && ! empty($conf->global->MAIN_GOOGLE_AN_ID)) { if (($conf->dol_use_jmobile != 4)) diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index af1ba72f8f6bd..c46fbc309a8f9 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1810,10 +1810,11 @@ SocialNetworkSetup=Setup of module Social Networks EnableFeatureFor=Enable features for %s VATIsUsedIsOff=Note: The option to use sales Tax or VAT has been set to Off in the menu %s - %s, so Sale tax or Vat used will always be 0 for sales. SwapSenderAndRecipientOnPDF=Swap sender and recipient address on PDF +FeatureSupportedOnTextFieldsOnly=Warning, feature supported on text fields only ##### Resource #### ResourceSetup=Configuration du module Resource UseSearchToSelectResource=Use a search form to choose a resource (rather than a drop-down list). DisabledResourceLinkUser=Disable feature to link a resource to users DisabledResourceLinkContact=Disable feature to link a resource to contacts ConfirmUnactivation=Confirm module reset -OnMobileOnly=On small screen (smartphone) only \ No newline at end of file +OnMobileOnly=On small screen (smartphone) only