Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

New answers tagged

0 votes

Custom textfield element, different $form_state value and element '#value' value

This can be done via Form API callback implementation: Inside module/src/Element/ElementClass.php, in public function getInfo() {} define a callback, e.g. processMyElement under '#process' key: public ...
user avatar
0 votes

Disable a field if another field is disabled

You can't do this with states here is what the docs says The following states may be used when checking values of other fields: empty filled checked unchecked expanded collapsed value So, for this ...
user avatar
0 votes

Hide/show additional fields depending on whether the checkbox is checked using formstate and hook_from_alter

There are several options to do what you want. #states form property This allows to show and hide, enable, disable, collapse, show and more actions on elements using JS. See Conditional Form Fields. ...
user avatar
  • 6,916
0 votes

$form_state->setValue() doesn't save value

You can use $form_state->setValue('VALUE_NAME', VALUE_PASSING); Like - public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state);...
user avatar
3 votes

AJAX in a plugin form results in "The specified #ajax callback is empty or not callable."

Thanks to Clives link, for reasons I am not 100% on the configuration forms for a Context plugin the AJAX callback needs to do this: /** * Trigger form rebuild. * * @param array $form * @...
user avatar
  • 26.3k
0 votes

How to hide a fieldset

When you unset the form fields inside fieldset it should not be shown automatically, but you can also implement hook_field_widget_WIDGET_TYPE_form_alter() in your module for other cases. You can use ...
user avatar
1 vote
Accepted

Changing the Moderation State Control Box input to a textarea

I was able to achieve it with a hook. We can add the below PHP to a custom module. Make sure to change the name of MYMODULE below. /** * Implements hook_form_FORM_ID_alter(). */ function ...
user avatar
  • 627
1 vote

How to refresh and reload (with ajax?) order checkout panes and order calculation independent from commerce cart refresh (e.g. billing address change)

So you want to refresh some content in the page that's not part of the checkout form? Basically, this can be done using an Ajax callback and one or more Ajax callback commands: https://www.drupal.org/...
user avatar
  • 111
0 votes
Accepted

How to add a submission handler to a form class on Drupal 8?

It looks like the problem reported in the question details have been resolved and the code in the question seems to be working. However for anybody reaching this page trying to find an answer to the ...
user avatar
  • 882
0 votes

How to add an unique wrapper id to a widget element?

If you have multiple wrappers on the same page you can't rely solely on Html::getUniqueId. You need to add as much predictable information as available. For example in a single field widget element ...
user avatar
  • 87.1k
0 votes

how to order grouped fields in the sidebar on a node form

Using weight -99 makes it appear on top in my installation. Weight -10 moves it nicely below the 'author' box, which is where I want it.
user avatar
1 vote
Accepted

Clear field value when edit node

HOOK_form_alter should be ok, then empty the field default value. $form[YOURFIELD]['default_value'] = '';
user avatar
0 votes

Can I add elements to a field widget with AJAX?

The point is, you can't modify Drupal's internal form structure in an Ajax callback. So you'll need a submit handler, either for the field or for the complete widget, do the form modifications there ...
user avatar
  • 111

Top 50 recent answers are included