Skip to content

Commit

Permalink
Add latlng and postcode fields
Browse files Browse the repository at this point in the history
  • Loading branch information
hnassr committed Sep 17, 2018
1 parent e867f92 commit f6116fd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions resources/js/components/DetailField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
<p class="text-90">{{ place.country }}</p>
</div>
</div>
<div class="flex" v-if="field.show_fields.indexOf('postcode') > -1">
<div class="w-1/6 py-4">
<h4 class="font-normal text-80">Postcode</h4>
</div>
<div class="w-3/4 py-4">
<p class="text-90">{{ place.postcode }}</p>
</div>
</div>
<div class="flex" v-if="field.show_fields.indexOf('administrative') > -1">
<div class="w-1/6 py-4">
<h4 class="font-normal text-80">Administrative</h4>
Expand All @@ -41,6 +49,14 @@
<p class="text-90">{{ place.name }}</p>
</div>
</div>
<div class="flex" v-if="field.show_fields.indexOf('latlng') > -1">
<div class="w-1/6 py-4">
<h4 class="font-normal text-80">LatLng</h4>
</div>
<div class="w-3/4 py-4">
<p class="text-90">{{ `${place.latlng.lat},${place.latlng.lng}` }}</p>
</div>
</div>
<div class="flex" v-if="field.show_fields.indexOf('full') > -1">
<div class="w-1/6 py-4">
<h4 class="font-normal text-80">Name</h4>
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
value: e.suggestion.value,
county: e.suggestion.county,
administrative: e.suggestion.administrative,
latlng: e.suggestion.latlng,
postcode: e.suggestion.postcode,
}
this.place = place.value;
this.value = JSON.stringify(place)
Expand Down
18 changes: 9 additions & 9 deletions resources/js/components/IndexField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
'city': 'name',
'full': 'value',
'countryCode': 'countryCode',
'latlng': 'latlng',
'postcode': 'postcode',
}
}
},
computed: {
placeN() {
if(this.field.value) {
return JSON.parse(this.field.value).value;
}
return null;
},
place() {
if(this.field.value) {
let index = this.available[this.field.index_field];
return JSON.parse(this.field.value)[index];
let parsed = JSON.parse(this.field.value);
if(index == 'latlng') {
return `${parsed[index].lat},${parsed[index].lng}`;
}
return parsed[index];
}
return null;
Expand Down
8 changes: 6 additions & 2 deletions src/Places.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Places extends Field

/**
* @param array $fields
* @options=["country", "county", "administrative", "city", "full", "countryCode"]
* @options=["country", "county", "administrative", "city", "full", "countryCode", "latlng", "postcode"]
* @return Places
*/
public function showFields(array $fields)
Expand All @@ -25,7 +25,7 @@ public function showFields(array $fields)

/**
* @param string $filed
* @options=["country", "county", "administrative", "city", "full", "countryCode"]
* @options=["country", "county", "administrative", "city", "full", "countryCode", "latlng", "postcode"]
* @return Places
*/
public function indexField(string $filed)
Expand All @@ -42,6 +42,10 @@ public function locale($locale)
return $this->withMeta(['place_locale' => $locale]);
}

/**
* @param array $countries
* @return Places
*/
public function countries(array $countries)
{
return $this->withMeta(['place_countries' => $countries]);
Expand Down

0 comments on commit f6116fd

Please sign in to comment.