C5-8.3: jquery code works in view but not in form

Permalink
I registered a jquery package in the controller:
public function on_start() {
        $this->set('app', $this->app);
        $al = \Concrete\Core\Asset\AssetList::getInstance();
        $al->register('javascript', 'my_table', 'blocks/my_table/my_table-3.0.0/mytable.full.min.js', array('position' => \Concrete\Core\Asset\Asset::ASSET_POSITION_HEADER, 'version' => '3.0.0'), 'my_table');
        $al->register('css', 'my_table', 'blocks/my_table/my_table-3.0.0/mytable.full.min.css', array('version' => '3.0.0'), 'my_table');
    }
    public function registerViewAssets($outputContent = '')
    {
        $this->requireAsset('javascript', 'jquery');
        $this->requireAsset('javascript', 'my_table');
        $this->requireAsset('css', 'my_table');
    }

Then I show it in view.php:
<div class="my-table">
    <div id="my_table"></div>
</div>
<script type="text/javascript">
$(function() {
    var data = [
    ["", "Tesla", "Volvo", "Toyota", "Honda"],
    ["2017", 10, 11, 12, 13],
    ["2018", 20, 11, 14, 13],
    ["2019", 30, 15, 12, 13]
    ];
    var container = document.getElementById('my_table');
    var hot = new Mytable(container, {
    data: data,
    rowHeaders: true,

This shows the table just fine. But if copy this exact piece of code into the form.php, the table is NOT shown.

Are assets registered in the block's controller available in the form?

linuxoid
 
hutman replied on at Permalink Reply
hutman
You need to require the assets in the add/edit functions too.
linuxoid replied on at Permalink Reply
linuxoid
No, that didn't work:
public function edit()
    {
        $this->requireAsset('javascript', 'my_table');
        $this->requireAsset('css', 'my_table');
    }
hutman replied on at Permalink Reply
hutman
You need both

public function add()
    {
        $this->requireAsset('javascript', 'jquery');
        $this->requireAsset('javascript', 'my_table');
        $this->requireAsset('css', 'my_table');
    }
    public function edit()
    {
        $this->requireAsset('javascript', 'jquery');
        $this->requireAsset('javascript', 'my_table');
        $this->requireAsset('css', 'my_table');
    }
linuxoid replied on at Permalink Reply
linuxoid
Nope, the form is empty
hutman replied on at Permalink Reply
hutman
What javascript errors, if any, do you have in your console? What is the code in the add/edit php files?
linuxoid replied on at Permalink Reply
linuxoid
Just by accident I missed the Save button and clicked on the form and the table appeared. Weird. So it IS actually there but doesn't show up until clicked on the form.

I don't use the add and edit files (they have default basics).

No JS errors.