FIX Mandatory field feature should works on textarea

Conflicts:
	htdocs/core/lib/functions.lib.php
This commit is contained in:
Laurent Destailleur 2018-12-15 18:11:40 +01:00
parent 33a91ff707
commit 527ad04ae8
4 changed files with 69 additions and 44 deletions

View File

@ -7150,7 +7150,7 @@ function printCommonFooter($zone='private')
if ($zone == 'private' && empty($conf->dol_use_jmobile)) if ($zone == 'private' && empty($conf->dol_use_jmobile))
{ {
print "\n"; print "\n";
print '/* JS CODE TO ENABLE to enable handler to switch left menu page (menuhider) */'."\n"; print '/* JS CODE TO ENABLE to manage handler to switch left menu page (menuhider) */'."\n";
print 'jQuery(".menuhider").click(function() {'; print 'jQuery(".menuhider").click(function() {';
print ' console.log("We click on .menuhider");'."\n"; print ' console.log("We click on .menuhider");'."\n";
//print " $('.side-nav').animate({width:'toggle'},200);\n"; // OK with eldy theme but not with md //print " $('.side-nav').animate({width:'toggle'},200);\n"; // OK with eldy theme but not with md
@ -7160,9 +7160,9 @@ function printCommonFooter($zone='private')
} }
// Management of focus and mandatory for fields // Management of focus and mandatory for fields
if ($action == 'create' || $action == 'edit') if ($action == 'create' || $action == 'edit' || (empty($action) && (preg_match('/new\.php/', $_SERVER["PHP_SELF"]))))
{ {
print '/* Code js to manage focus and mandatory form fields */'."\n"; print '/* JS CODE TO ENABLE to manage focus and mandatory form fields */'."\n";
$relativepathstring = $_SERVER["PHP_SELF"]; $relativepathstring = $_SERVER["PHP_SELF"];
// Clean $relativepathstring // Clean $relativepathstring
if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring); if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring);
@ -7191,8 +7191,10 @@ function printCommonFooter($zone='private')
{ {
foreach($defval as $paramkey => $paramval) foreach($defval as $paramkey => $paramval)
{ {
// Add property 'required' on input // Set focus on field
print 'jQuery("input[name=\''.$paramkey.'\']").focus();'."\n"; print 'jQuery("input[name=\''.$paramkey.'\']").focus();'."\n";
print 'jQuery("textarea[name=\''.$paramkey.'\']").focus();'."\n";
print 'jQuery("select[name=\''.$paramkey.'\']").focus();'."\n"; // Not really usefull, but we keep it in case of.
} }
} }
} }
@ -7221,6 +7223,7 @@ function printCommonFooter($zone='private')
{ {
// Add property 'required' on input // Add property 'required' on input
print 'jQuery("input[name=\''.$paramkey.'\']").prop(\'required\',true);'."\n"; print 'jQuery("input[name=\''.$paramkey.'\']").prop(\'required\',true);'."\n";
print 'jQuery("textarea[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 print 'jQuery("select[name=\''.$paramkey.'\']").prop(\'required\',true);'."\n"; // required on a select works only if key is "", this does not happen in Dolibarr
} }
} }

View File

@ -1819,7 +1819,7 @@ SocialNetworkSetup=Setup of module Social Networks
EnableFeatureFor=Enable features for <strong>%s</strong> EnableFeatureFor=Enable features for <strong>%s</strong>
VATIsUsedIsOff=Note: The option to use sales Tax or VAT has been set to <strong>Off</strong> in the menu %s - %s, so Sale tax or Vat used will always be 0 for sales. VATIsUsedIsOff=Note: The option to use sales Tax or VAT has been set to <strong>Off</strong> 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 SwapSenderAndRecipientOnPDF=Swap sender and recipient address on PDF
FeatureSupportedOnTextFieldsOnly=Warning, feature supported on text fields only FeatureSupportedOnTextFieldsOnly=Warning, feature supported on text fields only. Also an URL parameter action=create or action=edit' must be set OR page name must end with 'new.php' to trigger this feature.
EmailCollector=Email collector EmailCollector=Email collector
EmailCollectorDescription=Add a scheduled job and a setup page to scan regularly email boxes (using IMAP protocol) and record emails received into your application, at the right place and/or create some record automatically (like leads). EmailCollectorDescription=Add a scheduled job and a setup page to scan regularly email boxes (using IMAP protocol) and record emails received into your application, at the right place and/or create some record automatically (like leads).
NewEmailCollector=New Email Collector NewEmailCollector=New Email Collector

View File

@ -76,6 +76,8 @@ $extrafields = new ExtraFields($db);
$object = new Adherent($db); $object = new Adherent($db);
$user->loadDefaultValues();
/** /**
* Show header for new member * Show header for new member

View File

@ -422,11 +422,32 @@ class User extends CommonObject
return -2; return -2;
} }
$result = $this->loadDefaultValues();
if ($result < 0)
{
$this->error=$this->db->lasterror();
return -3;
}
}
return 1;
}
/**
* Load default value in property ->default_values
*
* @return int > 0 if OK, < 0 if KO
*/
function loadDefaultValues()
{
global $conf;
// Load user->default_values for user. TODO Save this in memcached ? // Load user->default_values for user. TODO Save this in memcached ?
$sql = "SELECT rowid, entity, type, page, param, value"; $sql = "SELECT rowid, entity, type, page, param, value";
$sql.= " FROM ".MAIN_DB_PREFIX."default_values"; $sql.= " FROM ".MAIN_DB_PREFIX."default_values";
$sql.= " WHERE entity IN (".$this->entity.",".$conf->entity.")"; $sql.= " WHERE entity IN (".($this->entity > 0 ? $this->entity.", " : "").$conf->entity.")"; // Entity of user (if defined) + current entity
$sql.= " AND user_id IN (0, ".$this->id.")"; $sql.= " AND user_id IN (0".($this->id > 0 ? ", ".$this->id : "").")"; // User 0 (all) + me (if defined)
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -459,17 +480,16 @@ class User extends CommonObject
} }
} }
$this->db->free($resql); $this->db->free($resql);
return 1;
} }
else else
{ {
$this->error=$this->db->lasterror(); dol_print_error($this->db);
return -3; return -1;
} }
} }
return 1;
}
/** /**
* Add a right to the user * Add a right to the user
* *