3 namespace Drupal\ajax_forms_test\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Form constructor for the Ajax Command display form.
13 class AjaxFormsTestCommandsForm extends FormBase {
18 public function getFormId() {
19 return 'ajax_forms_test_ajax_commands_form';
25 public function buildForm(array $form, FormStateInterface $form_state) {
28 // Shows the 'after' command with a callback generating commands.
29 $form['after_command_example'] = [
30 '#value' => $this->t("AJAX 'After': Click to put something after the div"),
33 'callback' => 'ajax_forms_test_advanced_commands_after_callback',
35 '#suffix' => '<div id="after_div">Something can be inserted after this</div>',
38 // Shows the 'alert' command.
39 $form['alert_command_example'] = [
40 '#value' => $this->t("AJAX 'Alert': Click to alert"),
43 'callback' => 'ajax_forms_test_advanced_commands_alert_callback',
47 // Shows the 'append' command.
48 $form['append_command_example'] = [
49 '#value' => $this->t("AJAX 'Append': Click to append something"),
52 'callback' => 'ajax_forms_test_advanced_commands_append_callback',
54 '#suffix' => '<div id="append_div">Append inside this div</div>',
57 // Shows the 'before' command.
58 $form['before_command_example'] = [
59 '#value' => $this->t("AJAX 'before': Click to put something before the div"),
62 'callback' => 'ajax_forms_test_advanced_commands_before_callback',
64 '#suffix' => '<div id="before_div">Insert something before this.</div>',
67 // Shows the 'changed' command without asterisk.
68 $form['changed_command_example'] = [
69 '#value' => $this->t("AJAX changed: Click to mark div changed."),
72 'callback' => 'ajax_forms_test_advanced_commands_changed_callback',
74 '#suffix' => '<div id="changed_div"> <div id="changed_div_mark_this">This div can be marked as changed or not.</div></div>',
76 // Shows the 'changed' command adding the asterisk.
77 $form['changed_command_asterisk_example'] = [
78 '#value' => $this->t("AJAX changed: Click to mark div changed with asterisk."),
81 'callback' => 'ajax_forms_test_advanced_commands_changed_asterisk_callback',
85 // Shows the Ajax 'css' command.
86 $form['css_command_example'] = [
87 '#value' => $this->t("Set the '#box' div to be blue."),
90 'callback' => 'ajax_forms_test_advanced_commands_css_callback',
92 '#suffix' => '<div id="css_div" style="height: 50px; width: 50px; border: 1px solid black"> box</div>',
95 // Shows the Ajax 'data' command. But there is no use of this information,
96 // as this would require a javascript client to use the data.
97 $form['data_command_example'] = [
98 '#value' => $this->t("AJAX data command: Issue command."),
101 'callback' => 'ajax_forms_test_advanced_commands_data_callback',
103 '#suffix' => '<div id="data_div">Data attached to this div.</div>',
106 // Shows the Ajax 'invoke' command.
107 $form['invoke_command_example'] = [
108 '#value' => $this->t("AJAX invoke command: Invoke addClass() method."),
111 'callback' => 'ajax_forms_test_advanced_commands_invoke_callback',
113 '#suffix' => '<div id="invoke_div">Original contents</div>',
116 // Shows the Ajax 'html' command.
117 $form['html_command_example'] = [
118 '#value' => $this->t("AJAX html: Replace the HTML in a selector."),
121 'callback' => 'ajax_forms_test_advanced_commands_html_callback',
123 '#suffix' => '<div id="html_div">Original contents</div>',
126 // Shows the Ajax 'insert' command.
127 $form['insert_command_example'] = [
128 '#value' => $this->t("AJAX insert: Let client insert based on #ajax['method']."),
131 'callback' => 'ajax_forms_test_advanced_commands_insert_callback',
132 'method' => 'prepend',
134 '#suffix' => '<div id="insert_div">Original contents</div>',
137 // Shows the Ajax 'prepend' command.
138 $form['prepend_command_example'] = [
139 '#value' => $this->t("AJAX 'prepend': Click to prepend something"),
142 'callback' => 'ajax_forms_test_advanced_commands_prepend_callback',
144 '#suffix' => '<div id="prepend_div">Something will be prepended to this div. </div>',
147 // Shows the Ajax 'remove' command.
148 $form['remove_command_example'] = [
149 '#value' => $this->t("AJAX 'remove': Click to remove text"),
152 'callback' => 'ajax_forms_test_advanced_commands_remove_callback',
154 '#suffix' => '<div id="remove_div"><div id="remove_text">text to be removed</div></div>',
157 // Shows the Ajax 'restripe' command.
158 $form['restripe_command_example'] = [
160 '#value' => $this->t("AJAX 'restripe' command"),
162 'callback' => 'ajax_forms_test_advanced_commands_restripe_callback',
164 '#suffix' => '<div id="restripe_div">
165 <table id="restripe_table" style="border: 1px solid black" >
166 <tr id="table-first"><td>first row</td></tr>
167 <tr ><td>second row</td></tr>
172 // Demonstrates the Ajax 'settings' command. The 'settings' command has
173 // nothing visual to "show", but it can be tested via SimpleTest and via
175 $form['settings_command_example'] = [
177 '#value' => $this->t("AJAX 'settings' command"),
179 'callback' => 'ajax_forms_test_advanced_commands_settings_callback',
183 // Shows the Ajax 'add_css' command.
184 $form['add_css_command_example'] = [
186 '#value' => $this->t("AJAX 'add_css' command"),
188 'callback' => 'ajax_forms_test_advanced_commands_add_css_callback',
194 '#value' => $this->t('Submit'),
203 public function submitForm(array &$form, FormStateInterface $form_state) {