I would like to add the Ajax callback settings to my custom composite webform element in the twig file. Is this possible? The callback function is in my custom module. This is NOT a computed twig situation. The Webform is created entirely from D8 webform GUI.

Custom composite has qty, code, description, price. Using the callback to verify code and update the description and price. Could something like below be put in the twig file?

'#ajax' => (
    'callback' => 'validate_srvform_items',
    'event' => 'change',
    'progress' => array(
      'type' => 'throbber',
      'message' => t('Populating line item...'),
  • 1
    The '#ajax' should added in your .module file not in the twig file, for example in hook_form_alter something like $form['some_field']['#ajax'] = [ 'callback' => 'validate_srvform_items', 'event' => 'change', 'progress' => [ 'type' => 'throbber', 'message' => t('Populating line item...'), ] ] take a look drupal.org/docs/8/api/javascript-api/…
    – berramou
    Nov 9, 2019 at 15:26
  • That link is very helpful, I never ran across it in my searches. Super.
    – DStrider
    Nov 11, 2019 at 15:10
  • Cool I'm glad that helped (y)
    – berramou
    Nov 11, 2019 at 15:14

1 Answer 1


You can create a form alter function in your module file and then add the callback property to the respective field

$form['actions']['submit']['#ajax'] = [
  'callback' => 'callback',
  'event' => 'click',

See also

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.