New answers tagged

0

Remove the 'wrapper' => 'first' that exist in the example_select. Set '#ajax'=> 'wrapper' elements to 'first', actually this is the id of element that will be updated, in your case <div id="first"> that you create using the prefix and suffix in $form['example_select2'] This is an extra step, for some reason it will work but you'll get an error ...


0

The below code is working well forme. public function myAjaxCallback(array &$form, FormStateInterface $form_state) { if ($selectedValue = $form_state->getValue('example_select')) { $arr = array('1' => 'Nice way', '2' => 'Good way'); $form['example_select2']['#options'] = $arr; } $form_state->setRebuild(TRUE); $response = new ...


1

Taking a blind guess: Your context matches the entire parent container, so you can't filter by "new ones only" with context. But as a workaround you could specify a more explicit find to filter only new ones: This will add .i-was-here-first to every views row present on document ready: $(document).ready(function($) { $('.views-infinite-scroll-content-...


2

You can pass down your region's ID as parameters to your route. For example: <a class="use-ajax" data-dialog-options="{&quot;width&quot;:550, &quot;dialogClass&quot;: &quot;my-region-class&quot; }" data-dialog-type="modal" href="/route/to/custom/form/this-region">...</a> As explained here you can add arguments from the ...


2

To use state for checkboxes element, you should target the specific element by JQuery selector, all elements they have the name="field_select_shipping" with value attribute different so try to target the input with both attributes try with the following to show adresse_home only if home and colissimo checkbox checked: $form['input']['adresse_home'] = [ ...


0

Your approach is right but you have the wrong syntax. $form['input']['adresse_home'] = [ '#type' => 'textfield', '#title' => 'Adresse', '#required' => false, '#states' => [ 'visible' => [ ':input[name^="field_select_shipping"]' => [['checked' => 'true'], ['value' => 'home']], // Omitted the rest. ], ]; ...


1

Drupal 8 doesn't cache Ajax forms anymore, so you can't get properties of the form object set in the initial form build. see Bypass form caching by default for forms using #ajax. Forms are only cached as rendered form. Put the entity id in a hidden form element to load the entity before saving. Add the entity cache tag to the form if you use default values ...


0

To add to Berdir's answer. If you are working with a custom entity. Its best to redefine the label method on the custom entity declaration for the autocomplete to work. Simply creating a EntityReferenceSelection plugin will not work with autocomplete since the autocomplete classes reference the label of an entity and there is no clear workaround that I ...


0

There are some methods provided in the ajax library of core docroot/core/misc/ajax.es6.js to allow you to add the loading message/icon to the your page. Drupal.theme.ajaxProgressThrobber Drupal.theme.ajaxProgressIndicatorFullscreen Drupal.theme.ajaxProgressMessage Simply call them like $('body').after(Drupal.theme....


0

I read somewhere that I couldn't use $form_state in a form hook Not quite. If hook_form_alter() is being executed for the first time, then yes, $form_state can't be used to get a field's value because $form_state['values'] will not be set. However, if hook_form_alter() is being re-executed, like from an #ajax callback, then $form_state['values'] will be ...


0

You can add effects to command like this: $command = ajax_command_replace($selector, $html); $command['effect'] = 'fade'; $command['speed'] = 2000; // Speed in ms.


Top 50 recent answers are included