N°1318 - multiple choice in a template - first step

This commit is contained in:
acognet
2023-06-05 23:26:58 +02:00
parent 6abf65bfb7
commit 413a798510
4 changed files with 24 additions and 10 deletions

View File

@@ -26,4 +26,15 @@ namespace Combodo\iTop\Form\Field;
*/
class TagSetObjectField extends MultipleSelectObjectField
{
function SetCurrentValue($currentValue)
{
if ($currentValue != null) {
$this->currentValue = $currentValue;
} else {
$this->currentValue = "";
}
return $this;
}
}

View File

@@ -18,6 +18,7 @@ use Combodo\iTop\Form\Field\SelectObjectField;
use Combodo\iTop\Form\Field\StringField;
use Combodo\iTop\Form\Field\SubFormField;
use Combodo\iTop\Form\Field\TagSetField;
use Combodo\iTop\Form\Field\TagSetObjectField;
use Combodo\iTop\Form\Field\TextAreaField;
use Combodo\iTop\Renderer\Console\FieldRenderer\ConsoleSelectObjectFieldRenderer;
use Combodo\iTop\Renderer\Console\FieldRenderer\ConsoleSimpleFieldRenderer;

View File

@@ -26,12 +26,14 @@ use Combodo\iTop\Application\UI\Base\Component\Input\InputUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Input\Select\SelectOptionUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Component\Input\SelectUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlockUIBlockFactory;
use Combodo\iTop\Core\MetaModel\FriendlyNameType;
use Combodo\iTop\Form\Field\SelectObjectField;
use Combodo\iTop\Form\Validator\MandatoryValidator;
use Combodo\iTop\Renderer\BlockRenderer;
use Combodo\iTop\Renderer\FieldRenderer;
use DBObjectSet;
use Dict;
use MetaModel;
use UIExtKeyWidget;
/**
@@ -188,9 +190,7 @@ EOF
$aValues = $this->oField->GetCurrentValue();
$sId = $this->oField->GetGlobalId();
// N°4792 - load only the required fields
$aFieldsToLoad = [];
$aComplementAttributeSpec = MetaModel::GetNameSpec($oAllowedValues->GetClass(), FriendlyNameType::COMPLEMENTARY);
$sFormatAdditionalField = $aComplementAttributeSpec[0];
$aAdditionalField = $aComplementAttributeSpec[1];
@@ -200,12 +200,14 @@ EOF
$sClassAllowed = $oAllowedValues->GetClass();
$bAddingValue = true;
$aFieldsToLoad[$sClassAllowed] = $aAdditionalField;
$sObjectImageAttCode = MetaModel::GetImageAttributeCode($sClassAllowed);
if (!empty($sObjectImageAttCode)) {
$aFieldsToLoad[$sClassAllowed][] = $sObjectImageAttCode;
}
$aFieldsToLoad[$sClassAllowed][] = 'friendlyname';
}
$sObjectImageAttCode = MetaModel::GetImageAttributeCode($sClassAllowed);
if (!empty($sObjectImageAttCode)) {
$aFieldsToLoad[$sClassAllowed][] = $sObjectImageAttCode;
}
$aFieldsToLoad[$sClassAllowed][] = 'friendlyname';
$oAllowedValues->OptimizeColumnLoad($aFieldsToLoad);
$oSelect = SelectUIBlockFactory::MakeForSelectWithLabel($this->oField->GetLabel(), $this->oField->GetDescription(), $this->oField->GetGlobalId());
@@ -213,7 +215,7 @@ EOF
$oSelect->AddSubBlock(SelectOptionUIBlockFactory::MakeForSelectOption(
$oObj->GetKey(),
$oObj->GetName(),
in_array($oObj->GetKey(), $aValues, true))
is_null($aValues) ? false : in_array($oObj->GetKey(), $aValues, true) === true)
);
}
$oOutput->AddJs(

View File

@@ -220,7 +220,7 @@ EOF
\IssueLog::Error('valeur:'.json_encode($this->oField->GetCurrentValue()));
foreach ($this->oField->GetChoices() as $sChoice => $sLabel) {
// Note : The test is a double equal on purpose as the type of the value received from the XHR is not always the same as the type of the allowed values. (eg : string vs int)
$oSelect->AddOption(SelectOptionUIBlockFactory::MakeForSelectOption($sChoice, $sLabel, in_array($sChoice, $this->oField->GetCurrentValue()) === true));
$oSelect->AddOption(SelectOptionUIBlockFactory::MakeForSelectOption($sChoice, $sLabel, is_null($this->oField->GetCurrentValue()) ? false : in_array($sChoice, $this->oField->GetCurrentValue()) === true));
}
$oValue->AddSubBlock($oSelect);
$oValue->AddSubBlock(new Html('<span class="form_validation"></span>'));
@@ -260,7 +260,7 @@ JS
$iId = 1;
foreach ($this->oField->GetChoices() as $sChoice => $sLabel) {
$oCheckBox = InputUIBlockFactory::MakeForInputWithLabel($sLabel, ''.$this->oField->GetGlobalId(), $sChoice, $this->oField->GetGlobalId().'_'.$iId, "checkbox");
$oCheckBox->GetInput()->SetIsChecked(in_array($sChoice, $aValues) === true);
$oCheckBox->GetInput()->SetIsChecked(is_null($aValues) ? false : in_array($sChoice, $aValues) === true);
$oCheckBox->SetBeforeInput(false);
$oCheckBox->GetInput()->AddCSSClass('ibo-input--label-right');
$oCheckBox->GetInput()->AddCSSClass('ibo-input-checkbox');