How to initiate a date picker when template is loaded remotely from controller action I have a controller action which returns JSON with a rendered template.  This template uses date picker form fields.  How can the date picker JS be initialized since the html is returned through JSON. I would have thought since the date picker field includes the necessary JS within {%js%} tag during template render it would be initialized. Could it be the timing of render vs adding the template html to the DOM? (Craft 3)

$view = $this-&gt;getView();

$html = $view-&gt;renderTemplate('_modal',['values' =&gt; $values, 'siteId' =&gt; $siteId]);
$headHtml = $view-&gt;getHeadHtml();

return $this-&gt;asJson(['html' =&gt; $html, 'headHtml' =&gt; $headHtml]);
Since your controller returns json you'll probably have a Javascript function that calls this controller so you can initialize it at the moment you receive the html.

Besides that you can as well include Javascript in your Craft::$app-&gt;getView()-&gt;registerJs class.