I use the API Form of Drupal 8 to create my form. I had an ajax callback on a field:
$form['association']['numero'] = array(
'#type' => 'textfield',
'#title' => t('foo'),
'#size' => 10,
'#maxlength' => 10,
'#suffix' => '<div id="ajax_error"></div>',
'#ajax' => [
'callback' => '::fetchApiData',
'event' => 'change',
'prevent' => 'click',
],
);
with my callback function :
public function fetchApiData(array $form, FormStateInterface $form_state)
{
return 'foo';
}
It's all working fine, but i want to trigger the callback when the user writes 10 characters precisely. Does anyone has a solution for that?