Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: YieldStudio/nova-google-autocomplete
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.2.0
Choose a base ref
...
head repository: YieldStudio/nova-google-autocomplete
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.3.0
Choose a head ref
  • 6 commits
  • 11 files changed
  • 2 contributors

Commits on Jul 9, 2023

  1. Update CHANGELOG

    JamesHemery authored and github-actions[bot] committed Jul 9, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    llucax Leandro Lucarella
    Copy the full SHA
    057afaf View commit details

Commits on Aug 16, 2023

  1. Copy the full SHA
    7910b44 View commit details
  2. Fix styling

    JamesHemery authored and github-actions[bot] committed Aug 16, 2023
    Copy the full SHA
    ecc4b9a View commit details
  3. feat: update translations

    JamesHemery committed Aug 16, 2023
    Copy the full SHA
    dc7a5b9 View commit details
  4. build

    JamesHemery committed Aug 16, 2023
    Copy the full SHA
    f613180 View commit details
  5. Merge pull request #8 from YieldStudio/1.3.0

    1.3.0
    JamesHemery authored Aug 16, 2023
    Copy the full SHA
    bde12c5 View commit details
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,18 @@ All notable changes to `nova-google-autocomplete` will be documented in this fil

Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## 1.2.0 - 2023-07-09

### What's Changed

- Added compatibility with whitecube/nova-flexible-content by @beneverard in https://github.com/YieldStudio/nova-google-autocomplete/pull/6

### New Contributors

- @beneverard made their first contribution in https://github.com/YieldStudio/nova-google-autocomplete/pull/6

**Full Changelog**: https://github.com/YieldStudio/nova-google-autocomplete/compare/1.1.0...1.2.0

## 1.1.0 - 2022-08-01

### What's Changed
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -71,6 +71,21 @@ AddressMetadata::make('long')->fromValue('longitude')->disabled(),
AddressMetadata::make('long')->fromValue('longitude')->invisible(),
```

By default, the formatted address will be stored on the property provided in the GoogleAutocomplete field. If you don't want to store it, you can use the `dontStore` method:


```php
use YieldStudio\NovaGoogleAutocomplete\AddressMetadata;
use YieldStudio\NovaGoogleAutocomplete\GoogleAutocomplete;

// Formatted address will not be stored
GoogleAutocomplete::make('Address')->withValues(['latitude', 'longitude'])->dontStore(),

// This field will be stored
AddressMetadata::make('lat')->fromValue('latitude'),
AddressMetadata::make('long')->fromValue('longitude'),
```

### Combine Values

If you want to concatenate certain elements of the geocoded object that is returned by Google, using `{{` and `}}`, wrap the key like you would above; like so:
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions dist/js/field.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <http://feross.org>
* @license MIT
*/

/*!
* vuex v4.1.0
* (c) 2022 Evan You
* @license MIT
*/

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
17 changes: 11 additions & 6 deletions resources/js/components/AddressMetadata/FormField.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<template>
<div :class="{ invisible: field.invisible }">
<DefaultField :field="field">
<DefaultField
:field="field"
:errors="errors"
:show-help-text="showHelpText"
:full-width-content="fullWidthContent"
>
<template #field>
<input
:id="field.name"
type="text"
:disabled="field.disabled"
class="w-full form-control form-input form-input-bordered"
:class="errorClasses"
:placeholder="field.name"
:placeholder="field.placeholder"
v-model="value"
/>
<p v-if="hasError" class="help-text error-text mt-2 text-danger">
{{ firstError }}
</p>
</template>
</DefaultField>
</div>
@@ -25,8 +27,11 @@ import { FormField, HandlesValidationErrors } from 'laravel-nova';
export default {
mixins: [FormField, HandlesValidationErrors],
props: ['resourceName', 'resourceId', 'field'],
mounted() {
Nova.$on('address-metadata-clear', () => {
this.value = '';
});
if (this.field.asJson) {
Nova.$on('address-metadata-update', locationObject => {
this.value = JSON.stringify(locationObject);
62 changes: 43 additions & 19 deletions resources/js/components/GoogleAutocomplete/FormField.vue
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
<template>
<DefaultField :field="field">
<DefaultField
:field="field"
:errors="errors"
:show-help-text="showHelpText"
:full-width-content="fullWidthContent"
>
<template #field>
<div class="form-group">
<vue-google-autocomplete
ref="address"
:id="field.attribute"
class="w-full form-control form-input form-input-bordered"
:class="errorClasses"
:country="field.countries"
:types="field.type"
:placeholder="value.trim().length === 0 ? field.name : __('update_address')"
v-model="value"
v-on:keypress.enter.prevent=""
v-on:placechanged="getAddressData"
/>
<vue-google-autocomplete
ref="searchField"
:id="field.attribute"
class="w-full form-control form-input form-input-bordered"
:class="errorClasses"
:country="field.countries"
:types="field.type"
:placeholder="placeholder"
v-model="search"
v-on:keypress.enter.prevent=""
v-on:placechanged="getAddressData"
/>
<div v-if="!field.dontStore && value && value.trim().length > 0">
<span class="inline-block mt-1 italic">{{
__('nga_current_address', { address: value })
}}</span>
<button @click="clear" type="button" class="text-red-500 inline-block ml-2">
{{ __('nga_clear') }}
</button>
</div>
<p v-if="hasError" class="help-text error-text mt-2 text-danger">
{{ firstError }}
</p>
</template>
</DefaultField>
</template>
@@ -30,17 +38,33 @@ export default {
components: { VueGoogleAutocomplete },
mixins: [FormField, HandlesValidationErrors],
props: ['resourceName', 'resourceId', 'field'],
data: function() {
return {
address: '',
search: '',
value: '',
};
},
computed: {
placeholder() {
if (this.field.placeholder) {
return this.field.placeholder;
}
return this.__('nga_search');
},
},
methods: {
clear() {
this.$refs.searchField.$refs.autocomplete.value = '';
this.value = '';
Nova.$emit('address-metadata-clear');
},
getAddressData(addressData, placeResultData) {
// Save current data address as a string
this.handleChange(placeResultData.formatted_address);
this.$refs.searchField.$refs.autocomplete.value = '';
const retrievedAddress = {};
// Emmit events to by catch up for the other AddressMetadata fields
4 changes: 3 additions & 1 deletion resources/lang/en.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"update_address": "Update the address if needed..."
"nga_current_address": "Current value: :address",
"nga_clear": "Clear",
"nga_search": "Search address"
}
4 changes: 3 additions & 1 deletion resources/lang/es.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"update_address": "Actualice la dirección si es necesario..."
"nga_current_address": "Valor actual: :address",
"nga_clear": "Suprima",
"nga_search": "Buscar una dirección"
}
4 changes: 3 additions & 1 deletion resources/lang/fr.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"update_address": "Mettez à jour l'adresse si nécessaire..."
"nga_current_address": "Valeur actuelle: :address",
"nga_clear": "Effacer",
"nga_search": "Recherchez une adresse"
}
2 changes: 1 addition & 1 deletion src/FieldServiceProvider.php
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ public function boot(): void
Nova::serving(function (ServingNova $event) {
Nova::script('google-autocomplete', __DIR__ . '/../dist/js/field.js');
Nova::remoteScript('https://maps.googleapis.com/maps/api/js?key='.config('nova-google-autocomplete.api_key').'&libraries=places');
Nova::translations(__DIR__ . '/../resources/lang/' . app()->getLocale() . '.json');
Nova::translations(resource_path('lang/vendor/nova-google-autocomplete/' . app()->getLocale() . '.json'));
});
}
}
5 changes: 5 additions & 0 deletions src/GoogleAutocomplete.php
Original file line number Diff line number Diff line change
@@ -28,6 +28,11 @@ public function countries(string|array $list): self
]);
}

public function dontStore(): self
{
return $this->fillUsing(fn () => null)->onlyOnForms()->withMeta(['dontStore' => true]);
}

/**
* Pass a place type
* https://developers.google.com/places/supported_types#table3