Ajax callback never called / triggered I'm working on a payment gateway, so I've created a BasePaymentOffsiteForm form where I'm trying to make an ajax callback, but it is not working.
Can you help me to know what is wrong with my code?
    $form = parent::buildConfigurationForm($form, $form_state);

    $form['content'] = [
      '#type' =&gt; 'container',
      '#prefix' =&gt; '&lt;div id=&quot;validate-phone-number&quot;&gt;',
      '#suffix' =&gt; '&lt;/div&gt;',
    ];

    $form['content']['mobile_phone'] = [
      '#type'   =&gt; 'textfield',
      '#title'  =&gt; $this-&gt;t('Mobile phone'),
    ];

    $form['content']['validate_client'] = [
      '#type' =&gt; 'button',
      '#value' =&gt; $this-&gt;t('Validate Client'),
      '#ajax' =&gt; [
        '#callback' =&gt; [get_class($this), 'clientValidateForm'],
        'event' =&gt; 'click',
        'wrapper' =&gt; 'validate-phone-number',
      ],
    ];

    $form['content']['cancel'] = [
      '#type' =&gt; 'link',
      '#title' =&gt; $this-&gt;t('Cancel'),
      '#url' =&gt; Url::fromUri($form['#cancel_url']),
    ];


    return $form;
  }

  public static function clientValidateForm(array $form, FormStateInterface $form_state) {
    $form['submit'] = [
      '#type' =&gt; 'submit',
      '#value' =&gt; 'Pay',
    ];
    return $form['submit'];
  }

It never gets in cientValidateForm method.
You're never making it to your callback because you don't have your #ajax array defined correctly, callback should not be defined as a hashed key. Take a look at the Adding an AJAX event example on d.o.
This should work:
$form['content']['validate_client'] = [
  '#type' =&gt; 'button',
  '#value' =&gt; $this-&gt;t('Validate Client'),
  '#ajax' =&gt; [
    // Change the callback key and update your callback value.
    'callback' =&gt; [$this, 'clientValidateForm'],
    'event' =&gt; 'click',
    'wrapper' =&gt; 'validate-phone-number',
  ],
];

Also note that Jaypan is right, you can't define new elements in your validation callback so you'll have to change that too. You may want to set a $form_state value in your validation handler and use that to add your element inside your build method. You may also need to update the wrapper value in your #ajax definition to align with the other changes.