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))
{
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 ' console.log("We click on .menuhider");'."\n";
//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
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"];
// Clean $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)
{
// Add property 'required' on input
// Set focus on field
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
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
}
}

View File

@ -1819,7 +1819,7 @@ SocialNetworkSetup=Setup of module Social Networks
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.
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
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

View File

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

View File

@ -422,45 +422,9 @@ class User extends CommonObject
return -2;
}
// Load user->default_values for user. TODO Save this in memcached ?
$sql = "SELECT rowid, entity, type, page, param, value";
$sql.= " FROM ".MAIN_DB_PREFIX."default_values";
$sql.= " WHERE entity IN (".$this->entity.",".$conf->entity.")";
$sql.= " AND user_id IN (0, ".$this->id.")";
$resql = $this->db->query($sql);
if ($resql)
{
while ($obj = $this->db->fetch_object($resql))
{
if (! empty($obj->page) && ! empty($obj->type) && ! empty($obj->param))
{
// $obj->page is relative URL with or without params
// $obj->type can be 'filters', 'sortorder', 'createform', ...
// $obj->param is key or param
$pagewithoutquerystring=$obj->page;
$pagequeries='';
if (preg_match('/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) // There is query param
{
$pagewithoutquerystring=$reg[1];
$pagequeries=$reg[2];
}
$this->default_values[$pagewithoutquerystring][$obj->type][$pagequeries?$pagequeries:'_noquery_'][$obj->param]=$obj->value;
//if ($pagequeries) $this->default_values[$pagewithoutquerystring][$obj->type.'_queries']=$pagequeries;
}
}
// Sort by key, so _noquery_ is last
if(!empty($this->default_values)) {
foreach($this->default_values as $a => $b)
{
foreach($b as $c => $d)
{
krsort($this->default_values[$a][$c]);
}
}
}
$this->db->free($resql);
}
else
$result = $this->loadDefaultValues();
if ($result < 0)
{
$this->error=$this->db->lasterror();
return -3;
@ -470,6 +434,62 @@ class User extends CommonObject
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 ?
$sql = "SELECT rowid, entity, type, page, param, value";
$sql.= " FROM ".MAIN_DB_PREFIX."default_values";
$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 > 0 ? ", ".$this->id : "").")"; // User 0 (all) + me (if defined)
$resql = $this->db->query($sql);
if ($resql)
{
while ($obj = $this->db->fetch_object($resql))
{
if (! empty($obj->page) && ! empty($obj->type) && ! empty($obj->param))
{
// $obj->page is relative URL with or without params
// $obj->type can be 'filters', 'sortorder', 'createform', ...
// $obj->param is key or param
$pagewithoutquerystring=$obj->page;
$pagequeries='';
if (preg_match('/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) // There is query param
{
$pagewithoutquerystring=$reg[1];
$pagequeries=$reg[2];
}
$this->default_values[$pagewithoutquerystring][$obj->type][$pagequeries?$pagequeries:'_noquery_'][$obj->param]=$obj->value;
//if ($pagequeries) $this->default_values[$pagewithoutquerystring][$obj->type.'_queries']=$pagequeries;
}
}
// Sort by key, so _noquery_ is last
if(!empty($this->default_values)) {
foreach($this->default_values as $a => $b)
{
foreach($b as $c => $d)
{
krsort($this->default_values[$a][$c]);
}
}
}
$this->db->free($resql);
return 1;
}
else
{
dol_print_error($this->db);
return -1;
}
}
/**
* Add a right to the user
*