New answers tagged forms
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 ...
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 ...
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.
...
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);...
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
* @...
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 ...
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 ...
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/...
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 ...
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 ...
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.
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'] = '';
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 ...
Top 50 recent answers are included
Related Tags
forms × 67007 × 2096
8 × 1393
ajax × 987
theming × 536
users × 400
nodes × 389
webforms × 303
javascript × 278
hooks × 276
views × 230
entities × 224
files × 203
6 × 197
blocks × 137
commerce × 116
emails × 95
database × 89
taxonomy-terms × 88
routes × 88
redirection × 88
media × 87
9 × 79
comments × 73
datetime × 68