5.7 Custom Block Type - Edit dialog with $(document).ready()
Permalink 1 user found helpful
In 5.7, there seems to be an issue with the way $(document).ready() is called when the edit.php dialog is loaded.
Here's what's happening:
When I first go into edit mode and click "Edit Block", the edit dialog appears and $(document).ready() fires as expected.
However, if I click Save or Cancel in the Edit dialog and then click "Edit Block" again, the the edit dialog appears, but $(document).ready() doesn't fire.
Here's an example of some code I'm using as a test:
application/blocks/example/controller.php
application/blocks/example/edit/script.js
Is there a different jQuery event that I should be using that fires every time the edit dialog is loaded?
Here's what's happening:
When I first go into edit mode and click "Edit Block", the edit dialog appears and $(document).ready() fires as expected.
However, if I click Save or Cancel in the Edit dialog and then click "Edit Block" again, the the edit dialog appears, but $(document).ready() doesn't fire.
Here's an example of some code I'm using as a test:
application/blocks/example/controller.php
public function on_start() { $al = \Concrete\Core\Asset\AssetList::getInstance(); $al->register('javascript', 'example', 'blocks/example/edit/script.js'); } public function edit() { $this->requireAsset('javascript', 'example'); }
application/blocks/example/edit/script.js
$(document).ready(function() { alert('ready'); });
Is there a different jQuery event that I should be using that fires every time the edit dialog is loaded?
https://github.com/concrete5/concrete5-5.7.0/issues/1355...
You can just use Concrete.event.fire() instead:
application/blocks/example/edit.php
application/blocks/example/auto.js