diff --git a/sources/form/field/field.class.inc.php b/sources/form/field/field.class.inc.php index ba2bb6b943..1162fd1249 100644 --- a/sources/form/field/field.class.inc.php +++ b/sources/form/field/field.class.inc.php @@ -58,7 +58,8 @@ abstract class Field public function __construct($sId, Closure $onFinalizeCallback = null) { $this->sId = $sId; - $this->sGlobalId = 'field_' . $sId . '_' . uniqid(); + // No space in such an id, that could be used as a DOM node id + $this->sGlobalId = 'field_' . str_replace(' ', '_', $sId) . '_' . uniqid(); $this->sLabel = static::DEFAULT_LABEL; $this->bHidden = static::DEFAULT_HIDDEN; $this->bReadOnly = static::DEFAULT_READ_ONLY; diff --git a/sources/form/field/selectobjectfield.class.inc.php b/sources/form/field/selectobjectfield.class.inc.php index 083e8a89f1..1f4ba755ef 100644 --- a/sources/form/field/selectobjectfield.class.inc.php +++ b/sources/form/field/selectobjectfield.class.inc.php @@ -33,12 +33,18 @@ class SelectObjectField extends Field protected $iMaximumComboLength; protected $iMinAutoCompleteChars; + protected $iControlType; + + const CONTROL_SELECT = 1; + const CONTROL_RADIO_VERTICAL = 2; + public function __construct($sId, Closure $onFinalizeCallback = null) { parent::__construct($sId, $onFinalizeCallback); $this->oSearch = null; $this->iMaximumComboLength = null; $this->iMinAutoCompleteChars = 3; + $this->iControlType = self::CONTROL_SELECT; } public function SetSearch(DBSearch $oSearch) @@ -56,6 +62,11 @@ class SelectObjectField extends Field $this->iMinAutoCompleteChars = $iMinAutoCompleteChars; } + public function SetControlType($iControlType) + { + $this->iControlType = $iControlType; + } + /** * Sets if the field is mandatory or not. * Setting the value will automatically add/remove a MandatoryValidator to the Field @@ -100,4 +111,9 @@ class SelectObjectField extends Field { return $this->iMinAutoCompleteChars; } + + public function GetControlType() + { + return $this->iControlType; + } } diff --git a/sources/renderer/console/consoleformrenderer.class.inc.php b/sources/renderer/console/consoleformrenderer.class.inc.php index ae7982e7c3..938bb3e2dd 100644 --- a/sources/renderer/console/consoleformrenderer.class.inc.php +++ b/sources/renderer/console/consoleformrenderer.class.inc.php @@ -37,6 +37,7 @@ class ConsoleFormRenderer extends FormRenderer $this->AddSupportedField('StringField', 'ConsoleSimpleFieldRenderer'); $this->AddSupportedField('SelectField', 'ConsoleSimpleFieldRenderer'); $this->AddSupportedField('TextAreaField', 'ConsoleSimpleFieldRenderer'); + $this->AddSupportedField('RadioField', 'ConsoleSimpleFieldRenderer'); $this->AddSupportedField('SelectObjectField', 'ConsoleSelectObjectFieldRenderer'); $this->AddSupportedField('SubFormField', 'ConsoleSubFormFieldRenderer'); } diff --git a/sources/renderer/console/fieldrenderer/consoleselectobjectfieldrenderer.class.inc.php b/sources/renderer/console/fieldrenderer/consoleselectobjectfieldrenderer.class.inc.php index 02342c0ca0..0c753ae71e 100644 --- a/sources/renderer/console/fieldrenderer/consoleselectobjectfieldrenderer.class.inc.php +++ b/sources/renderer/console/fieldrenderer/consoleselectobjectfieldrenderer.class.inc.php @@ -18,13 +18,13 @@ namespace Combodo\iTop\Renderer\Console\FieldRenderer; -use Combodo\iTop\Form\Field\StringField; use Combodo\iTop\Form\Validator\MandatoryValidator; -use Combodo\iTop\Form\Validator\Validator; use \Dict; use \DBObjectSet; use Combodo\iTop\Renderer\FieldRenderer; use Combodo\iTop\Renderer\RenderingOutput; +use Combodo\iTop\Form\Field\SelectObjectField; + class ConsoleSelectObjectFieldRenderer extends FieldRenderer { @@ -73,6 +73,7 @@ class ConsoleSelectObjectFieldRenderer extends FieldRenderer if ($iCount > $iMaxComboLength) { // Auto-complete + // $sEditType = 'autocomplete'; $aExtKeyParams = array(); $aExtKeyParams['iFieldSize'] = 10; @@ -101,9 +102,44 @@ class ConsoleSelectObjectFieldRenderer extends FieldRenderer $oOutput->AddCssFile($sFile); } } + elseif($this->oField->GetControlType() == SelectObjectField::CONTROL_RADIO_VERTICAL) + { + // Radio buttons (vertical) + // + $sEditType = 'radio'; + $bVertical = true; + $idx = 0; + $bMandatory = $this->oField->GetMandatory(); + $value = $this->oField->GetCurrentValue(); + $sId = $this->oField->GetGlobalId(); + $oOutput->AddHtml('
'); + while ($oObject = $oSet->Fetch()) + { + $iObject = $oObject->GetKey(); + $sLabel = $oObject->Get('friendlyname'); + if (($iCount == 1) && $bMandatory) + { + // When there is only once choice, select it by default + $sSelected = ' checked'; + } + else + { + $sSelected = ($value == $iObject) ? ' checked' : ''; + } + $oOutput->AddHtml(" "); + if ($bVertical) + { + $oOutput->AddHtml("
\n"); + } + $idx++; + } + $oOutput->AddHtml('
'); + $oOutput->AddHtml(""); + } else { // Drop-down select + // $sEditType = 'select'; $oOutput->AddHtml(''); + $oOutput->AddHtml(''.htmlentities($sCurrentLabel, ENT_QUOTES, 'UTF-8').''); + } + else + { + $bVertical = true; + $idx = 0; + $bMandatory = $this->oField->GetMandatory(); + $value = $this->oField->GetCurrentValue(); + $sId = $this->oField->GetGlobalId(); + $oOutput->AddHtml('
'); + $aChoices = $this->oField->GetChoices(); + foreach ($aChoices as $sChoice => $sLabel) + { + if ((count($aChoices)== 1) && $bMandatory) + { + // When there is only once choice, select it by default + $sSelected = ' checked'; + } + else + { + $sSelected = ($value == $sChoice) ? ' checked' : ''; + } + $oOutput->AddHtml(" "); + if ($bVertical) + { + $oOutput->AddHtml("
\n"); + } + $idx++; + } + $oOutput->AddHtml('
'); + $oOutput->AddHtml(""); + } + $oOutput->AddHtml(''); + $oOutput->AddHtml(''); + break; } $oOutput->AddHtml(''); $oOutput->AddHtml(''); @@ -141,6 +184,7 @@ EOF break; case 'Combodo\\iTop\\Form\\Field\\SelectField': + case 'Combodo\\iTop\\Form\\Field\\RadioField': $oOutput->AddJs( <<oField->GetGlobalId()}").off("change").on("change", function(){