New answers tagged

0 votes

Call #ajax when a checkbox is checked or unchecked

Its been too long with 7 that I don't recall all the innerworkings of #ajax with forms, but I wound up just building a new form and returning that. Now it works every single time. Likely not the best ...
  • 26.9k
0 votes

How to get checkboxes values in a form?

Sometimes when using $form_state->getValue() you can end up with the first checkbox as checked even if it isn't checked, getUserInput() is more accurate. What you can do instead is this: $selection ...
3 votes

Replacement for hook_user_presave() for saving values captured in the user form to the user profile

As pointed out from @cilefen, the $edit parameter has been removed from the parameter passed to hook_user_presave(), which (starting from Drupal 8) is now documented under hook_ENTITY_TYPE_presave(). $...
  • 95k
0 votes

Default value of a 'managed file' field

Simple settings form with Managed file field with default value: Config file form: public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('bk.settings'); ...
0 votes

How to identify ajax request in the exposed form of the View?

This hook seems to be not very useful in a Views context. You don't get much information, not even the view name. In an Ajax request Views removes any POST data from the request before executing the ...
  • 90.4k
0 votes

remove "last saved" and "author" fields in from

I had the same problem with claro and a group content node edit form. These did NOT work (...
0 votes

How do I alter the form submission handler?

On Drupal 8 or 9 it's almost the same solution : Add a hook in a custom module file and a custom function : File my_module.module : <?php use Drupal\Core\Form\FormStateInterface; /** * ...
0 votes

How add conditional required field

For required state you have to target the actual input as mentioned in Drupal documentation Example: $form['field_name']['widget']['0']['target_id'['#states'] = [ 'required' => [ ':input[name=...
  • 1
0 votes

How can I avoid fields being disabled on AJAX requests (attribute disabled) in Drupal?

I ended up with this solution // Disable [disabled] attribute on the input. const defaultBeforeSend = Drupal.Ajax.prototype.beforeSend; Drupal.Ajax.prototype.beforeSend = ...
  • 266

Top 50 recent answers are included