Hi there. Im configuring on click event in the fullcalendar extension from philipfrenzel.
App does nothing on click.
I can’t find my mistakes. Developer console in chrome doesn’t say anything.
Here’s the AssetBundle
namespace app\assets;
use yii\web\AssetBundle;
class EventAsset extends Assetbundle
{
public $sourcePath = "@app/assets";
public $js = [
'js/main.js',
];
}
Well, if I understand this correctly you have EventController which controls the whole proccess. actionIndex shows the view with fullcalendar. For now I do not consider other things (modals, form, etc.)
First thing I see is that in index.php you register asset AppAsset but here should be EventAsset.
Also, where is your main.js file located ?
I see you are using property $sourcePath. It should be used only when your files from asset are stored in a directory which is not web-accessible. More info: https://www.yiiframework.com/doc/guide/2.0/en/structure-assets
You could try this:
create directory js in /web
move your main.js file to /web/js
change asset file to:
namespace app\assets;
use yii\web\AssetBundle;
class EventAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
];
public $js = [
'js/main.js',
];
public $depends = [
'yii\web\YiiAsset',
'yii\web\JqueryAsset',
'yii\bootstrap\BootstrapAsset',
];
}
I created a directory in /web where I put my main.js file. Also I changed my EventAsset.php with the code you provided and registered my EventAsset.php file in index.php, but it still doesn’t do the work. I believe the problem is in my main.js file.
Previous steps were neccessary to ensure correct loading of main.js file. You should now see this file in generated source code of page among other *.js files. I think that your main.js file has at least one error. This cannot work:
It’s because $.get is function for AJAX GET request and it doesn’t have method .on(). This method should be used on objects from DOM.
I have not enough time for testing your code now and will be offline for a few days. Maybe when I return I could test it properly and find the solution.
In case this might help anyone, I have an edit button in the view event modal that closes the view modal and opens an edit modal, so event click looks like this:
I have some news. Now the modal appears. I mean, After some tests it pops up. I don’t know how but I tried in Google Chrome’s private mode and it appeared and now it pops up in normal mode. It seems to be a bug.