form : disable the label linking to checkboxes and radio if more than 1 checkbox/radio is set

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5929 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2020-04-16 18:39:56 +00:00
parent 714f4e815e
commit a7e5726f39

View File

@@ -781,6 +781,8 @@ class formfield
{
// No $this->multiple, $this->rows $this->cols $this->placeholder,
// $this->maxlength
if (! is_array ($this->titles) || count ($this->titles) === 0)
$this->titles = array ("");
$res = "";
$res .= "<div class='form-group";
if (isset ($this->errors))
@@ -788,12 +790,17 @@ class formfield
$res .= "'>\n";
if ($this->label !== "")
{
$res .= " <label class='col-sm-$this->titlewidth control-label' for='".
$this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES);
if (is_array ($this->titles) && count ($this->titles) > 1)
$res .= "_0";
$res .= "'";
$res .= " <label class='col-sm-$this->titlewidth control-label'";
if (is_array ($this->titles) && count ($this->titles) == 1 &&
reset ($this->titles) === "")
{
// If more than one title is set, the main label is unusable, so
// do not link it to the checkbox
// If there is no label on the checkbox, this label must be set
$res .= " for='". $this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES);
$res .= "'";
}
if (isset ($this->hidden) && $this->hidden !== FALSE)
$res .= " style='display:none'";
$res .= ">";
@@ -805,8 +812,6 @@ class formfield
$res .= "</label>\n";
}
$res .= " <div class='col-sm-$this->fieldwidth'>\n";
if (! is_array ($this->titles) || count ($this->titles) === 0)
$this->titles = array ("");
foreach ($this->titles as $key=>$val)
{
$res .= " <div class='checkbox'>\n";
@@ -818,9 +823,9 @@ class formfield
$res .= "' value='unset'";
$res .= "/>";
$res .= "<label for='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES);
if (count ($this->titles) > 1)
$res .= "$key";
$res .= "_$key";
$res .= "'>";
$res .= "<input type='checkbox'";
$res .= " name='$this->formName"."[";
@@ -1010,9 +1015,17 @@ class formfield
$res .= "'>\n";
if ($this->label !== "")
{
$res .= " <label class='col-sm-$this->titlewidth control-label' for='".
$this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_0'";
$res .= " <label class='col-sm-$this->titlewidth control-label'";
if (is_array ($this->titles) && count ($this->titles) == 1 &&
reset ($this->titles) === "")
{
// If more than one title is set, the main label is unusable, so
// do not link it to the radio
// If there is no label on the checkbox, this label must be set
$res .= " for='". $this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES);
$res .= "'";
}
if (isset ($this->hidden) && $this->hidden !== FALSE)
$res .= " style='display:none'";
$res .= ">";
@@ -1499,6 +1512,8 @@ class formfield
{
// No $this->multiple, $this->rows $this->cols $this->placeholder,
// $this->maxlength
if (! is_array ($this->titles) || count ($this->titles) === 0)
$this->titles = array ("");
$res = "";
$res .= "<div class='form-group";
if (isset ($this->errors))
@@ -1511,11 +1526,16 @@ class formfield
$res .= " <label";
if ($this->titlewidth > 0)
$res .= " class='col-sm-$this->titlewidth col-form-label'";
$res .= " for='". $this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES);
if (is_array ($this->titles) && count ($this->titles) > 1)
$res .= "_0";
$res .= "'";
if (is_array ($this->titles) && count ($this->titles) == 1 &&
reset ($this->titles) === "")
{
// If more than one title is set, the main label is unusable, so
// do not link it to the checkbox
// If there is no label on the checkbox, this label must be set
$res .= " for='". $this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES);
$res .= "'";
}
if (isset ($this->hidden) && $this->hidden !== FALSE)
$res .= " style='display:none'";
$res .= ">";
@@ -1527,8 +1547,6 @@ class formfield
$res .= "</label>\n";
}
$res .= " <div class='col-sm-$this->fieldwidth'>\n";
if (! is_array ($this->titles) || count ($this->titles) === 0)
$this->titles = array ("");
foreach ($this->titles as $key=>$val)
{
$res .= " <div class='form-check'>\n";
@@ -1602,9 +1620,9 @@ class formfield
}
$res .= "/>\n";
$res .= " <label for='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES);
if (count ($this->titles) > 1)
$res .= "$key";
$res .= "_$key";
$res .= "' class ='form-check-label'";
$res .= ">";
$res .= "$val</label>\n";
@@ -1755,8 +1773,16 @@ class formfield
$res .= " <label";
if ($this->titlewidth > 0)
$res .= " class='col-sm-$this->titlewidth col-form-label'";
$res .= " for='". $this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_0'";
if (is_array ($this->titles) && count ($this->titles) == 1 &&
reset ($this->titles) === "")
{
// If more than one title is set, the main label is unusable, so
// do not link it to the radio
// If there is no label on the checkbox, this label must be set
$res .= " for='". $this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES);
$res .= "'";
}
if (isset ($this->hidden) && $this->hidden !== FALSE)
$res .= " style='display:none'";
$res .= ">";