From 465388b5e35524851845c5ab880cafc8eaa25bc8 Mon Sep 17 00:00:00 2001 From: Benjamin Dalsass Date: Mon, 12 Jun 2023 17:25:03 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B0803=20-=20Allow=20display=20&=20edition?= =?UTF-8?q?=20of=20attributes=20on=20n:n=20relations=20on=20Portal=20-=20I?= =?UTF-8?q?ssue=20when=20selecting=20links=20rows=20with=20checkbox=20-=20?= =?UTF-8?q?Change=20linked=20set=20field=20validation=20to=20prevent=20che?= =?UTF-8?q?cking=20host=20id=20-1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sources/Form/Field/LinkedSetField.php | 23 ++++++--- .../BsLinkedSetFieldRenderer.php | 10 ++-- .../FieldRenderer/BsSimpleFieldRenderer.php | 50 +++++++++---------- 3 files changed, 47 insertions(+), 36 deletions(-) diff --git a/sources/Form/Field/LinkedSetField.php b/sources/Form/Field/LinkedSetField.php index 30da524f6..22d5f3349 100644 --- a/sources/Form/Field/LinkedSetField.php +++ b/sources/Form/Field/LinkedSetField.php @@ -358,17 +358,26 @@ class LinkedSetField extends Field /** @var ormLinkSet $oSet */ $oSet = $this->GetCurrentValue(); + // retrieve displayed attributes + $aAttributesToDisplayCodes = $this->GetLnkAttributesToDisplay(true); + + // validate each links... /** @var \DBObject $oItem */ foreach ($oSet as $oItem) { - list($bRes, $aIssues) = $oItem->CheckToWrite(); - if ($bRes === false) { - foreach ($aIssues as $sIssue) { - $sItem = $oItem->Get('friendlyname') != '' ? $oItem->Get('friendlyname') : Dict::S('UI:Links:NewItem'); - $this->AddErrorMessage(''.$sItem.' : '.$sIssue); + $aChanges = $oItem->ListChanges(); + foreach ($aChanges as $sAttCode => $value) { + if (!in_array($sAttCode, $aAttributesToDisplayCodes)) { + continue; + } + $res = $oItem->CheckValue($sAttCode); + if ($res !== true) { + $sAttLabel = $this->GetLabel($sAttCode); + $sItem = $oItem->Get('friendlyname') != '' ? $oItem->Get('friendlyname') : Dict::S('UI:Links:NewItem'); + $sIssue = Dict::Format('Core:CheckValueError', $sAttLabel, $sAttCode, $res); + $this->AddErrorMessage(''.$sItem.' : '.$sIssue); + $bValid = false; } - $bValid = false; } - } $oSet->Rewind(); diff --git a/sources/Renderer/Bootstrap/FieldRenderer/BsLinkedSetFieldRenderer.php b/sources/Renderer/Bootstrap/FieldRenderer/BsLinkedSetFieldRenderer.php index df31f842c..4d89534fa 100644 --- a/sources/Renderer/Bootstrap/FieldRenderer/BsLinkedSetFieldRenderer.php +++ b/sources/Renderer/Bootstrap/FieldRenderer/BsLinkedSetFieldRenderer.php @@ -136,7 +136,7 @@ EOF $sLabelGeneralCheckbox = utils::EscapeHtml(Dict::S('Core:BulkExport:CheckAll').' / '.Dict::S('Core:BulkExport:UncheckAll')); $sSelectionOptionHtml = ($this->oField->GetReadOnly()) ? 'false' : '{"style": "multi"}'; $sSelectionInputGlobalHtml = ($this->oField->GetReadOnly()) ? '' : ''; - $sSelectionInputHtml = ($this->oField->GetReadOnly()) ? '' : ''; + $sSelectionInputHtml = ($this->oField->GetReadOnly()) ? '' : ''; // - Output $oOutput->AddJs( <<GetValidatorsAsJson()}, 'on_validation_callback': function(){ - const aLinkedSetInputs = $('#{$sFieldWrapperId} input', this.element); + const aLinkedSetInputs = $('#{$sFieldWrapperId} input,select,textarea', this.element); aLinkedSetInputs.each(function(e){ const oInput = $(this); const aInputValidity = oInput[0].validity; diff --git a/sources/Renderer/Bootstrap/FieldRenderer/BsSimpleFieldRenderer.php b/sources/Renderer/Bootstrap/FieldRenderer/BsSimpleFieldRenderer.php index dc7789cc6..e2df1cb1a 100644 --- a/sources/Renderer/Bootstrap/FieldRenderer/BsSimpleFieldRenderer.php +++ b/sources/Renderer/Bootstrap/FieldRenderer/BsSimpleFieldRenderer.php @@ -55,6 +55,9 @@ class BsSimpleFieldRenderer extends BsFieldRenderer $sFieldMandatoryClass = ($this->oField->GetMandatory()) ? 'form_mandatory' : ''; $sFieldDescriptionForHTMLTag = ($this->oField->HasDescription()) ? 'data-tooltip-content="'.utils::HtmlEntities($this->oField->GetDescription()).'"' : ''; + // Prepare input validations tags + $sInputTags = $this->ComputeInputValidationTags($this->oField); + // Rendering field in edition mode if (!$this->oField->GetReadOnly() && !$this->oField->GetHidden()) { // HTML content @@ -82,9 +85,6 @@ class BsSimpleFieldRenderer extends BsFieldRenderer // - Help block $oOutput->AddHtml('
'); - // Prepare input validations tags - $sInputTags = $this->ComputeInputValidationTags($this->oField); - // - Value regarding the field type switch ($sFieldClass) { case 'Combodo\\iTop\\Form\\Field\\DateTimeField': @@ -111,7 +111,7 @@ EOF break; case 'Combodo\\iTop\\Form\\Field\\PasswordField': - $oOutput->AddHtml(''); + $oOutput->AddHtml(''); break; case 'Combodo\\iTop\\Form\\Field\\StringField': @@ -124,7 +124,7 @@ EOF case 'Combodo\\iTop\\Form\\Field\\SelectField': case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField': - $oOutput->AddHtml('oField->GetMultipleValuesEnabled()) ? 'multiple' : '').' class="form-control" '.$sInputTags.'>'); 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) $sSelectedAtt = ($this->oField->GetCurrentValue() == $sChoice) ? 'selected' : ''; @@ -148,29 +148,29 @@ EOF // Label $oOutput->AddHtml('
'); - if ($this->oField->GetLabel() !== '') { - $oOutput->AddHtml(''); - } - $oOutput->AddHtml('
'); + if ($this->oField->GetLabel() !== '') { + $oOutput->AddHtml(''); + } + $oOutput->AddHtml(''); - // Value - $oOutput->AddHtml('
'); - // - Help block - $oOutput->AddHtml('
'); - // First the edition area - $oOutput->AddHtml('
'); - $oOutput->AddHtml(''); - $oOutput->AddHtml('
'); - // Then the previous entries if necessary - if ($sFieldClass === 'Combodo\\iTop\\Form\\Field\\CaseLogField') { - $this->PreparingCaseLogEntries($oOutput); - } - $oOutput->AddHtml('
'); + // Value + $oOutput->AddHtml('
'); + // - Help block + $oOutput->AddHtml('
'); + // First the edition area + $oOutput->AddHtml('
'); + $oOutput->AddHtml(''); + $oOutput->AddHtml('
'); + // Then the previous entries if necessary + if ($sFieldClass === 'Combodo\\iTop\\Form\\Field\\CaseLogField') { + $this->PreparingCaseLogEntries($oOutput); + } + $oOutput->AddHtml('
'); - // Closing container - $oOutput->AddHtml(''); + // Closing container + $oOutput->AddHtml(''); - // Some additional stuff if we are displaying it with a rich editor + // Some additional stuff if we are displaying it with a rich editor if ($bRichEditor) { $aConfig = utils::GetCkeditorPref(); $aConfig['extraPlugins'] = 'codesnippet';