small java script problem in form

Hi, i’m new here, I guess this must be very trivial but my english is bad :wink:

I created a grid and form (_form.php) on which the user can input his location by moving a marker on the map (text fields are updated with latitude and longitude when moving the marker).

This works fine when open create/update directly. but it does not function when the form is called through the buttons on the grid, in the view (the map is not showing).

I’m new to yii and mvc… I guess it has to do with registering the JS but I have tried various ways and still the map is not showing in modal form view. (it only shows when loading create or update in a new browser tab)

Any hints are highly appreciated :slight_smile:

Use the Web Developer plugin and check the console for any javascript errors.

It might be you are registering your code in the wrong position. Check:

[color=#303336][font=inherit][size=2]$this[/size][/font][/color][color=#303336][font=inherit][size=2]->[/size][/font][/color][color=#303336][font=inherit][size=2]registerJsFile[/size][/font][/color][color=#303336][font=inherit][size=2]([/size][/font][/color][color=#7D2727][font=inherit][size=2]‘path/to/file.js’[/size][/font][/color][color=#303336][font=inherit][size=2],[/size][/font][/color][color=#303336][font=inherit][size=2] [/size][/font][/color][color=#303336][font=inherit][size=2][[/size][/font][/color][color=#7D2727][font=inherit][size=2]‘position’[/size][/font][/color][color=#303336][font=inherit][size=2] [/size][/font][/color][color=#303336][font=inherit][size=2]=> POS_XXXXX[/size][/font][/color]

[color=#242729][font=Arial,]View::POS_HEAD or [/font][/color][color=#242729][font=Arial,]View::POS_BEGIN or [/font][/color][color=#242729][font=Arial,]View::POS_END or [/font][/color][color=#242729][font=Arial,]View::POS_READY[/font][/color]





hi thanks,


$this->registerJsFile(‘localhost/scripty.js’, [‘depends’ => [yii\web\JqueryAsset::className()]]);

$this->registerJsFile(‘h**p://’, [‘depends’ => [\yii\web\JqueryAsset::className()]]);

to my view.php

does not work. tried yours. not getting it. the ** in http because i am ‘not allowed’ to add links.

I use firefox console not receiving any errors.

script is not included in generated page source.

Are your files being addded? Check the page source code.

Also, you shouldn’t use [color="#8b0000"]‘localhost/scripty’[/color]. If your scripts is under your app’s web folder, use:

$this->registerJsFile(’@web/scripty.js’, [‘depends’ => [\yii\web\JqueryAsset::className()], ‘position’ => View::POS_HEAD]);

Note: change ‘position’ according to the script documentation. Check this too:


Also, are you using $(’#id’)… or jQuery(’#id’)…?

Ediited because code tag isn’t working fine in Chrome


Reading around a bit, and because I need this feature in most views, I decided to include the java script through the AppAsset.php.

It does still function but only when calling CREATE/UPDATE in a separate window.

It does not function in modal when clicking on edit/create buttons in ajax crud (map does not show).

I have verified that all 4 scripts are being included and that they are located after the jquery (POS_END).

Why is the script not working in modal create/update? But it works when open create or update in new browser tab.


namespace frontend\assets;

use yii\web\AssetBundle;


  • Main frontend application asset bundle.


class AppAsset extends AssetBundle


public $basePath = '@webroot';

public $baseUrl = '@web';

public $css = [



public $js = [






public $depends = [





I’m still tapping in the dark here ^^ appreciate any hints.

Just bumping this up because i never got it to work