Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Field Address Google with Javascript error #5721

Closed
mrinaldidfs opened this issue Nov 22, 2024 · 4 comments
Closed

[Bug] Field Address Google with Javascript error #5721

mrinaldidfs opened this issue Nov 22, 2024 · 4 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@mrinaldidfs
Copy link

Bug report

By inserting the address_google field inside a crud all the other fields that use javascript (such as select2) stop working and in the console I find the following error:

Uncaught TypeError: google.maps.places is undefined
    bpFieldInitAddressGoogleElement http://domain.test/admin/organization/create:958
    initializeFieldsWithJavascript http://domain.test/admin/organization/create:1041
    jQuery 2
    initializeFieldsWithJavascript http://domain.test/admin/organization/create:1036
    <anonymous> http://domain.test/admin/organization/create:1097
    jQuery 13

The address Google Field work, but all other fields not

What I did

I inserted the address_google type field into a crud

CRUD::addField([
            'name' => 'google_address',
            'type' => 'address_google',
            'label' => 'Address',
            'wrapper' => ['class' => 'form-group col-md-12'],
            'store_as_json' => true
]);

What I expected to happen

to have the Google autocomplete suggestion in the field as soon as it is inserted

What happened

Google's suggestion works correctly but, following javascript errors, all the other fields are not displayed correctly

What I've already tried to fix it

I customized the field by placing it in the vendor/backpack/crud/fields folder
I added below the line with
if(typeof google === "undefined") { return; }
the following line
if(typeof google.maps.places === "undefined") { return; }

I also had to remove from the basset the part of the javascript script that contains the init of the field by removing it from the baset block
@bassetBlock('backpack/pro/fields/address-google-field.js')

Is it a bug in the latest version of Backpack?

After I run composer update backpack/crud the bug... is it still there?
yes

When I run php artisan backpack:version the output is:

PHP VERSION:

8.2.19

PHP EXTENSIONS:

Core, bcmath, calendar, ctype, date, filter, hash, iconv, json, SPL, pcre, random, readline, Reflection, session, standard, mysqlnd, tokenizer, zlib, libxml, dom, PDO, bz2, SimpleXML, xml, xmlreader, xmlwriter, openssl, curl, ftp, fileinfo, gd, intl, imap, mbstring, exif, mysqli, Phar, pdo_mysql, sodium, xsl, zip, redis, imagick, mongodb

LARAVEL VERSION:

11.33.2.0

BACKPACK PACKAGE VERSIONS:

backpack/basset: 1.3.6
backpack/crud: 6.7.42
backpack/editable-columns: 3.0.10
backpack/generators: v4.0.7
backpack/pro: 2.2.25
backpack/theme-tabler: 1.2.15

@pxpm
Copy link
Contributor

pxpm commented Nov 22, 2024

Hello @mrinaldidfs thanks for the question.

Make sure your API key has access to the following google API's:

Maps Javascript API
Places API
Geocoding API

I've just tested it, without any changes and everything is working as expected as long as my API has access to those 3 services.
image

I've just added it to the docs to make it more clear: https://backpackforlaravel.com/docs/6.x/crud-fields#address_google-pro

I am going to close this, please feel free to ping @karandatwani92 if you still experiencing issues and he can re-open this and help you out. 👍

@pxpm pxpm closed this as completed Nov 22, 2024
@pxpm pxpm added documentation Improvements or additions to documentation and removed Bug Priority: MUST labels Nov 22, 2024
@pxpm pxpm assigned karandatwani92 and unassigned pxpm Nov 22, 2024
@mrinaldidfs
Copy link
Author

Hi @pxpm
thanks for the quick response but the problem does not concern the functioning of the address_google field but in all the other fields (such as repeatable or relationship) which stop working.
The field work fine
immagine
but the relationship field don't
immagine
and in the console there is this error
immagine
the correct display of the contacts field is:
immagine

I therefore ask @karandatwani92 to please reopen this issue and help me to solve the problem.
With my fix all works fine but i don't want to have to customize the field

@karandatwani92
Copy link
Contributor

Hey @mrinaldidfs

I tested it now on my end, and it worked fine without affecting other select/relationship/etc fields.

@karandatwani92
Copy link
Contributor

Screenshot 2024-11-22 at 6 32 24 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
Status: Done
Development

No branches or pull requests

3 participants