ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
FormWithoutSubmitButtonsContextRenderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\UI\Renderer as RendererInterface;
28use LogicException;
29
31{
35 public function render(Component\Component $component, RendererInterface $default_renderer): string
36 {
37 if ($component instanceof Form\Standard) {
38 return $this->renderFormWithoutSubmitButtons($component, $default_renderer);
39 }
40
41 $this->cannotHandleComponent($component);
42 }
43
45 Form\Standard $component,
46 RendererInterface $default_renderer
47 ): string {
48 $tpl = $this->getTemplate("tpl.without_submit_buttons.html", true, true);
49
50 $this->maybeAddDedicatedName($component, $tpl);
51 $this->maybeAddRequired($component, $tpl);
52 $this->addPostURL($component, $tpl);
53 $this->maybeAddError($component, $tpl);
54
55 $tpl->setVariable("INPUTS", $default_renderer->render($component->getInputGroup()));
56
57 $enriched_component = $component->withAdditionalOnLoadCode(
58 static function (string $id) use ($component): string {
59 return "
60 // @TODO: we need to refactor the signal-management to prevent using jQuery here.
61 $(document).on('{$component->getSubmitSignal()}', function () {
62 let form = document.getElementById('$id');
63 if (!form instanceof HTMLFormElement) {
64 throw new Error(`Element '$id' is not an instance of HTMLFormElement.`);
65 }
66
67 // @TODO: we should use the triggering button as an emitter here. When doing
68 // so, please also change file.js processFormSubmissionHook().
69 form.requestSubmit();
70 });
71 ";
72 }
73 );
74
75 $id = $this->bindJavaScript($enriched_component) ?? $this->createId();
76 $tpl->setVariable("ID", $id);
77
78 return $tpl->get();
79 }
80}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This implements commonalities between all forms.
Definition: Form.php:34
addPostURL(Component\Input\Container\Form\FormWithPostURL $component, Template $tpl)
Definition: Renderer.php:72
maybeAddDedicatedName(Form\Form $component, Template $tpl)
Definition: Renderer.php:65
maybeAddRequired(Form\Form $component, Template $tpl)
Definition: Renderer.php:89
maybeAddError(Form\Form $component, Template $tpl)
Definition: Renderer.php:81
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
return true
Interface to templating as it is used in the UI framework.
Definition: Template.php:29
An entity that renders components to a string output.
Definition: Renderer.php:31