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]

[color=#242729][font=Arial,]

[/font][/color]

[color=#242729][font=Arial,]

[/font][/color]

hi thanks,

added:

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

$this->registerJsFile(‘h**p://maps.google.com/maps/api/js?libraries=places’, [‘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:

http://www.yiiframew…registerJsFile()-detail

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

Ediited because code tag isn’t working fine in Chrome

Hi,

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 = [


    'css/site.css',


];


public $js = [

‘h**ps://maps.google.com/maps/api/js?libraries=places’,

‘h**ps://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.min.js’,

‘h**ps://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.min.js’,

‘h**p://127.0.0.1/script.js’,

];


public $depends = [


    'yii\web\YiiAsset',


    'yii\bootstrap\BootstrapAsset',


];

}

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

Just bumping this up because i never got it to work