/** * Render output for an Inputfield * * @param Inputfield $inputfield The Inputfield to render * @param bool $renderValueMode * @return string Rendered output * */ public function ___renderInputfield(Inputfield $inputfield, $renderValueMode = false) { $collapsed = $inputfield->getSetting('collapsed'); $ajaxInputfield = $collapsed == Inputfield::collapsedYesAjax || $collapsed == Inputfield::collapsedBlankAjax && $inputfield->isEmpty(); $ajaxID = $this->wire('config')->ajax ? $this->wire('input')->get('renderInputfieldAjax') : ''; if ($ajaxInputfield && ($inputfield->required && $inputfield->isEmpty() || !$this->wire('user')->isLoggedin())) { // if an ajax field is empty, and is required, then we don't use ajax render mode // plus, we only allow ajax inputfields for logged-in users $ajaxInputfield = false; if ($collapsed == Inputfield::collapsedYesAjax) { $inputfield->collapsed = Inputfield::collapsedYes; } if ($collapsed == Inputfield::collapsedBlankAjax) { $inputfield->collapsed = Inputfield::collapsedBlank; } } if ($renderValueMode) { $inputfield->addClass('InputfieldRenderValue', 'wrapClass'); } $inputfield->renderReady($this, $renderValueMode); if ($ajaxInputfield) { $inputfieldID = $inputfield->attr('id'); if ($ajaxID && $ajaxID == $inputfieldID) { // render ajax inputfield $editable = $inputfield->editable(); if ($renderValueMode || !$editable) { echo $inputfield->renderValue(); } else { echo $inputfield->render(); echo "<input type='hidden' name='processInputfieldAjax[]' value='{$inputfieldID}' />"; } exit; } else { if ($ajaxID && $ajaxID != $inputfieldID && $inputfield instanceof InputfieldWrapper && $inputfield->getChildByName(str_replace('Inputfield_', '', $ajaxID))) { // nested ajax inputfield, within another ajax inputfield $in = $inputfield->getChildByName(str_replace('Inputfield_', '', $ajaxID)); return $this->renderInputfield($in, $renderValueMode); } else { // do not render ajax inputfield $url = $this->wire('input')->url(); $queryString = $this->wire('input')->queryString(); if (strpos($queryString, 'renderInputfieldAjax=') !== false) { // in case nested ajax request $queryString = preg_replace('/&?renderInputfieldAjax=[^&]+/', '', $queryString); } $url .= $queryString ? "?{$queryString}&" : "?"; $url .= "renderInputfieldAjax={$inputfieldID}"; $out = "<div class='renderInputfieldAjax'><input type='hidden' value='{$url}' /></div>"; if ($inputfield instanceof InputfieldWrapper) { // load assets they will need foreach ($inputfield->getAll() as $in) { $in->renderReady($inputfield, $renderValueMode); } } return $out; } } } if (!$renderValueMode && $inputfield->editable()) { return $inputfield->render(); } // renderValueMode $out = $inputfield->renderValue(); if (is_null($out)) { return ''; } if (!strlen($out)) { $out = ' '; } // prevent output from being skipped over return $out; }
/** * Render output for an Inputfield * * @param Inputfield $inputfield The Inputfield to render * @param bool $renderValueMode * @return string Rendered output * */ public function renderInputfield(Inputfield $inputfield, $renderValueMode = false) { $inputfield->renderReady($this, $renderValueMode); if (!$renderValueMode) { return $inputfield->render(); } // renderValueMode $out = $inputfield->renderValue(); if (is_null($out)) { return ''; } if (!strlen($out)) { $out = ' '; } // prevent output from being skipped over return $out; }