how to include web js file and apply jquery

Hi folks

i have developed script for google maps address

I have load js files like

<script src="http://maps.googleapis.com/maps/api/js?key=#@#$$$#&sensor=false&libraries=places"></script>

and fire jqyery on input element like address

<input type="text" name="address"  style="width: 500px;"></input>

var autocomplete = new google.maps.places.Autocomplete($("input[name=address]")[0], {});

How can i load this js on Account Module .. How Can i apply jquery this on  $("input[name=billing_address_street]")

I have put all js file content in JsGrouping But  not work ...

How Can i do ???

Tevfik Tümer Angel Magana Ramana Raju Santhana

  • Hi Mehul Bhandari

    First copy all the content from maps.googleapis js file into custom file name it as gmaps.js file and move that file into your custom folder i.e

    ./custom/gmaps.js

    then create new grouping

    ./custom/Extension/application/Ext/JSGroupings/gmapsGrouping.php

    <?php
    $js_groupings[] = $gmapsGrouping = array(
        'custom/gmaps.js' => 'include/javascript/gmapsGrouping.js'
       
    );
    

    Next, navigate to Admin > Repair > Quick Repair and Rebuild. The system will then rebuild the extensions and create the JSGrouping extension. Once completed, navigate to Admin > Repair > Rebuild JS Grouping Files. This will create the grouping file shown below:

    ./cache/include/javascript/gmapsGrouping.js

    Now under Accounts module custom/modules/Accounts/Clients/base/views/record/record.js file

    initialize function add the following code:

    this.on("render", this.Getmap, this);

    now outside the function

    Getmap: function(){

    var autocomplete = new google.maps.places.Autocomplete($("input[name=address]")[0], {});

    }

    Hope this Helps

    Best Regards

    S Ramana Raju

  • Hi Mehul

    It depends on SugarCRM version you are playing.

    Can you kindly let us know it?

    Cheers

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hi André Lopes

    i have already mentioned in question .

    sugar 7.7

  • Hi Ramana Raju Santhana

    Thanks ..

    only   ($("input[name=billing_address_city]")[0], {});

    not working

    any idea ??

  • HI Ramana Raju Santhana

    I have developed for Sugar 6.5 and its working Perfect ..

    getting problem here in 7.7

    Screenshot from 2016-07-21 12:27:32.png

  • Hi Mehul  Bhandari

    Can you try this and let me know

    var pacLocation = this.model.get('address');
    var autocomplete = new google.maps.places.Autocomplete(pacLocation,{});
    

    Hope this Helps!

    Best Regards

    S Ramana Raju

  • Hi Ramana Raju Santhana

    not worked

    error :

    Uncaught TypeError: a.getAttribute is not a function

  • HI Mehul  Bhandari

    Can i know file name and path where you have written this code

    Best Regards

    S Ramana Raju

  • Hi Ramana Raju Santhana

    i have write code in  custom/modules/Accounts/clients/base/views/create/create.js

    ({
         extendsFrom: 'CreateView',
        initialize: function(options) {
            this._super('initialize', [options]);
           
        this.on("render", this.Getmap, this);
           
        },
        Getmap: function(){
    
    
                var pacLocation = this.model.get('billing_address_city');
                var autocomplete = new google.maps.places.Autocomplete(pacLocation,{});   
                 console.log("000001111111");  
                google.maps.event.addListener(autocomplete, 'place_changed', function() {
                    console.log("00000");  
                    var place = autocomplete.getPlace();
    
    
                    console.log(place.address_components);
                    
    
    
        });
    
    
         },
        
    })
    
    
    
    
    
    
    
    
    
    
    
  • Hi Mehul  Bhandari

    Remove line this.on("render", this.Getmap, this); 

    and try it by events

    events: {

       'keyup input[name="billing_address_city"] ': 'Getmap'  

      }

    Kind Regards

    S Ramana Raju

1 2 3