Is it possible for a Drupal Ajax form to automatically fire a callback when a page is loaded?
I know this is possible using an external JS file and doing it through Drupal behaviors, however I would prefer to be able to do is straight from the Drupal form callback as this allows for less code and more security.
I am trying to do something like this:
$form['mark'] = ['#markup' => '<div id="mytestid">REPLACE ME</div>'];
$form['test'] = [
'#type' => 'textfield',
'#title' => 'My Title',
'#ajax' => [
'callback' => '::callback',
'event' => 'load',
],
];
The load
event doesn't work, which makes me think Drupal doesn't want to allow this type of functionality. When I use something like click
or mouseout
it does work. Is there some type of event here that I can use that will fire this ajax callback when the form loads? Or is it not possible this way?