feat(SelectAttribute) Hide existing values from choices

When in a multi-valuated attribute, do not propose existing values to be
 added a second time as it is not possible anyway.

issue #5536
parent 01b66aa4
......@@ -32,6 +32,11 @@ class SelectAttribute extends Attribute
protected $outputs = NULL;
protected $size = 1;
/*! \brief Valid values which should be hidden from rendered input
*
* Used by SetAttribute to hide used values */
protected $hiddenChoices;
/*! \brief The constructor of SelectAttribute
*
* \param string $label The label to show for this attribute
......@@ -112,6 +117,11 @@ class SelectAttribute extends Attribute
return $this->outputs;
}
function setHiddenChoices (array $choices)
{
$this->hiddenChoices = $choices;
}
function setRequired (bool $bool)
{
parent::setRequired($bool);
......@@ -159,10 +169,17 @@ class SelectAttribute extends Attribute
{
$smarty = get_smarty();
$id = $this->getHtmlId();
$smartyChoices = $this->choices;
$smartyChoices = array_values(array_diff($this->choices, $this->hiddenChoices));
$currentValue = $this->getValue();
if (in_array($currentValue, $this->hiddenChoices)) {
$currentValue = '';
}
if ($this->outputs !== NULL) {
$smartyOutputs = array_values($this->outputs);
/* Make sure choices and outputs are in the same order */
$smartyOutputs = [];
foreach ($smartyChoices as $choice) {
$smartyOutputs[] = $this->outputs[$choice];
}
} else {
$smartyOutputs = $this->choices;
}
......
......@@ -221,6 +221,9 @@ class SetAttribute extends Attribute
return;
}
$this->handleEditingValue();
if ($this->valueUnicity && ($this->attribute instanceOf SelectAttribute)) {
$this->attribute->setHiddenChoices($this->getValue());
}
if ($template) {
return $this->attribute->renderTemplateInput();
} else {
......@@ -238,6 +241,9 @@ class SetAttribute extends Attribute
if ($this->linearRendering || $readOnly) {
parent::renderAttribute($attributes, $readOnly, $readable, $writable);
} else {
if ($this->valueUnicity && ($this->attribute instanceOf SelectAttribute)) {
$this->attribute->setHiddenChoices($this->getValue());
}
$attributes[$this->getLdapName()] = [
'htmlid' => $this->getForHtmlId(),
'label' => '{literal}'.$this->getLabel().'{/literal}',
......
Markdown is supported
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