Commit a3c661c8 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Merge branch '5910-use-more-html5-input-types' into '1.4-dev'

Resolve "Use more HTML5 input types"

See merge request fusiondirectory/fd!429
parents 45858d23 bddf0fc9
......@@ -62,6 +62,15 @@ class CompositeAttribute extends Attribute
unset($attribute);
}
function setIsSubAttribute($bool)
{
parent::setIsSubAttribute($bool);
foreach ($this->attributes as &$attribute) {
$attribute->setIsSubAttribute($this->isSubAttribute);
}
unset($attribute);
}
function setAcl ($acl)
{
parent::setAcl($acl);
......
......@@ -108,7 +108,9 @@ class IntAttribute extends Attribute
$js = $this->managedAttributesJS();
$attributes['onChange'] = 'javascript:'.htmlentities($js, ENT_COMPAT, 'UTF-8');
}
if ($this->isRequired()) {
if ($this->isSubAttribute) {
$attributes['class'] = 'subattribute';
} elseif ($this->isRequired()) {
$attributes['required'] = 'required';
}
$display = $this->renderInputField('number', $id, $attributes);
......
......@@ -43,10 +43,17 @@ class SetAttribute extends Attribute
$values
);
$this->attribute = $attribute;
$this->attribute->setRequired(FALSE);
$this->attribute->setRequired(TRUE);
$this->attribute->setIsSubAttribute(TRUE);
$this->valueUnicity = $valueUnicity;
}
function setIsSubAttribute($bool)
{
parent::setIsSubAttribute($bool);
$this->attribute->setIsSubAttribute($this->isSubAttribute);
}
function setManagedAttributes (array $dontcare)
{
trigger_error('method setManagedAttributes is not supported for SetAttributes');
......@@ -231,18 +238,22 @@ class SetAttribute extends Attribute
parent::renderAttribute($attributes, $readOnly);
} else {
$attributes[$this->getLdapName()] = array(
'htmlid' => $this->getForHtmlId(),
'label' => '{literal}'.$this->getLabel().'{/literal}'.($this->isRequired() ? '{$must}' : ''),
'description' => ($this->isRequired() ? sprintf(_("%s (required)"), $this->getDescription()) : $this->getDescription()),
'input' => $this->renderAcl($this->renderOnlyFormInput()),
'htmlid' => $this->getForHtmlId(),
'label' => '{literal}'.$this->getLabel().'{/literal}'.($this->isRequired() ? '{$must}' : ''),
'description' => ($this->isRequired() ? sprintf(_("%s (required)"), $this->getDescription()) : $this->getDescription()),
'input' => $this->renderAcl($this->renderOnlyFormInput()),
'subattribute' => $this->isSubAttribute,
'required' => $this->isRequired(),
);
$this->handleEditingValue();
$this->attribute->renderAttribute($attributes, $readOnly);
$attributes[$this->getLdapName().'_buttons'] = array(
'htmlid' => 'add'.$this->getHtmlId(),
'label' => '',
'description' => '',
'input' => $this->renderAcl($this->renderButtons()),
'htmlid' => 'add'.$this->getHtmlId(),
'label' => '',
'description' => '',
'input' => $this->renderAcl($this->renderButtons()),
'subattribute' => TRUE,
'required' => FALSE,
);
}
}
......
......@@ -82,7 +82,9 @@ class StringAttribute extends Attribute
if ($this->html5pattern !== NULL) {
$attributes['pattern'] = '{literal}'.htmlentities($this->html5pattern, ENT_COMPAT, 'UTF-8').'{/literal}';
}
if ($this->isRequired()) {
if ($this->isSubAttribute) {
$attributes['class'] = 'subattribute';
} elseif ($this->isRequired()) {
$attributes['required'] = 'required';
}
$display = $this->renderInputField($this->inputType, $id, $attributes);
......@@ -159,7 +161,7 @@ class TextAreaAttribute extends StringAttribute
$id = $this->getHtmlId();
$display = '<textarea name="'.$id.'" id="'.$id.'"'.
($this->disabled ? ' disabled="disabled"' : '').
($this->isRequired() ? ' required="required"' : '').
($this->isSubAttribute ? ' class="subattribute"' : ($this->isRequired() ? ' required="required"' : '')).
'>'.
'{literal}'.htmlentities($this->getValue(), ENT_COMPAT, 'UTF-8').'{/literal}</textarea>';
return $this->renderAcl($display);
......
......@@ -82,6 +82,12 @@ class Attribute
/* \bried Array of booleans telling for each managing attributes if he's disabling us */
protected $managingAttributesOrders = array();
/* \bried If this is TRUE it means this attribute is not directly submitted with the form
* but is part of a multivalue attribute.
* It means it should not be set as required in the HTML form for instance.
*/
protected $isSubAttribute = FALSE;
/*! \brief The constructor of Attribute
*
* \param string $label The label to show for this attribute
......@@ -114,6 +120,11 @@ class Attribute
$this->manageAttributes($this->getValue());
}
function setIsSubAttribute($bool)
{
$this->isSubAttribute = $bool;
}
function setInLdap ($inLdap)
{
$this->inLdap = $inLdap;
......@@ -589,10 +600,12 @@ class Attribute
$input = $this->renderFormInput();
}
$attributes[$this->getLdapName()] = array(
'htmlid' => $this->getForHtmlId(),
'label' => '{literal}'.$this->getLabel().'{/literal}'.($this->isRequired() ? '{$must}' : ''),
'description' => ($this->isRequired() ? sprintf(_("%s (required)"), $this->getDescription()) : $this->getDescription()),
'input' => $input,
'htmlid' => $this->getForHtmlId(),
'label' => '{literal}'.$this->getLabel().'{/literal}'.($this->isRequired() ? '{$must}' : ''),
'description' => ($this->isRequired() ? sprintf(_("%s (required)"), $this->getDescription()) : $this->getDescription()),
'input' => $input,
'subattribute' => $this->isSubAttribute,
'required' => $this->isRequired(),
);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment