diff --git a/include/simpleplugin/attributes/class_CompositeAttribute.inc b/include/simpleplugin/attributes/class_CompositeAttribute.inc index 03bae4ca5d707c228ce624b5a56c8e49e4342caa..445a25c32cf1fbdbe4bcd8deb452c0c56c56b266 100644 --- a/include/simpleplugin/attributes/class_CompositeAttribute.inc +++ b/include/simpleplugin/attributes/class_CompositeAttribute.inc @@ -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); diff --git a/include/simpleplugin/attributes/class_IntAttribute.inc b/include/simpleplugin/attributes/class_IntAttribute.inc index 7ca5e42159b7a4d108befbededdd251e0b985cfe..d54cab6bb72cd5a960e8124596a1bcd75e294ad2 100644 --- a/include/simpleplugin/attributes/class_IntAttribute.inc +++ b/include/simpleplugin/attributes/class_IntAttribute.inc @@ -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); diff --git a/include/simpleplugin/attributes/class_SetAttribute.inc b/include/simpleplugin/attributes/class_SetAttribute.inc index 90d16938dd25347c0bd149aded872676067918cd..322ce22b980583643a586f4d236fee0895abe71b 100644 --- a/include/simpleplugin/attributes/class_SetAttribute.inc +++ b/include/simpleplugin/attributes/class_SetAttribute.inc @@ -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, ); } } diff --git a/include/simpleplugin/attributes/class_StringAttribute.inc b/include/simpleplugin/attributes/class_StringAttribute.inc index 3ea86764bf6477549fadd9ebe8fc1d2b3e5dd3aa..a51f6406861a4aebb982aaa4e36b8d8f403b0089 100644 --- a/include/simpleplugin/attributes/class_StringAttribute.inc +++ b/include/simpleplugin/attributes/class_StringAttribute.inc @@ -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); diff --git a/include/simpleplugin/class_Attribute.inc b/include/simpleplugin/class_Attribute.inc index 213415a460cc4b04d17d15e1d0915a11908ae271..337a24f1c4f9be56f44561343087a7174de24db0 100644 --- a/include/simpleplugin/class_Attribute.inc +++ b/include/simpleplugin/class_Attribute.inc @@ -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(), ); } }