namespace Combodo\iTop\Renderer\Bootstrap\FieldRenderer; use \Dict; use Combodo\iTop\Renderer\Bootstrap\BsFormRenderer; use Combodo\iTop\Renderer\FieldRenderer; use Combodo\iTop\Renderer\RenderingOutput; class BsSubFormFieldRenderer extends FieldRenderer { public function Render() { $oOutput = new RenderingOutput(); // Checking if subform has visible fields $bHasVisibleFields = false; foreach ($this->oField->GetForm()->GetFields() as $oSubFormField) { $sSubFormFieldClass = get_class($oSubFormField); // Note : This is a dirty hack for templates. As they show a label when there is no template, we have to detect it... if (($sSubFormFieldClass !== 'Combodo\iTop\Form\Field\HiddenField') && ($oSubFormField->GetId() !== '_no_template_')) { $bHasVisibleFields = true; } } // Showing subform if there are visible fields if (!$bHasVisibleFields) { $oOutput->AddHtml(''); } $oRenderer = new BsFormRenderer($this->oField->GetForm()); $aRenderRes = $oRenderer->Render(); $aFieldSetOptions = array( 'fields_list' => $aRenderRes, 'fields_impacts' => $this->oField->GetForm()->GetFieldsImpacts(), 'form_path' => $this->oField->GetForm()->GetId() ); $sFieldSetOptions = json_encode($aFieldSetOptions); $oOutput->AddJs( <<oField->GetGlobalId()}").field_set($sFieldSetOptions); $("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").subform_field({field_set: $("#fieldset_{$this->oField->GetGlobalId()}")}); EOF ); return $oOutput; } }