Skip to content

Commit 5bece31

Browse files
committed
Merge branch 'address-field'
2 parents 13a69f6 + 6a32b29 commit 5bece31

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ All Notable changes to `Backpack CRUD` will be documented in this file
2020
- Nothing
2121

2222

23+
## [3.1.24] - 2016-09-27
24+
25+
### Added
26+
- address field type - thanks to [Owen Melbourne](https://github.com/OwenMelbz);
27+
28+
2329
## [3.1.23] - 2016-09-27
2430

2531
### Added
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<!-- text input -->
2+
<div @include('crud::inc.field_wrapper_attributes') >
3+
<label>{!! $field['label'] !!}</label>
4+
5+
@if(isset($field['prefix']) || isset($field['suffix'])) <div class="input-group"> @endif
6+
@if(isset($field['prefix'])) <div class="input-group-addon">{!! $field['prefix'] !!}</div> @endif
7+
@if(isset($field['store_as_json']) && $field['store_as_json'])
8+
<input
9+
type="text"
10+
data-address="{&quot;field&quot;: &quot;{{$field['name']}}&quot;, &quot;full&quot;: {{isset($field['store_as_json']) && $field['store_as_json'] ? 'true' : 'false'}} }"
11+
@include('crud::inc.field_attributes')
12+
>
13+
<input type="hidden" value="{{ old($field['name']) ? old($field['name']) : (isset($field['value']) ? $field['value'] : (isset($field['default']) ? $field['default'] : '' )) }}" name="{{ $field['name'] }}">
14+
@else
15+
<input
16+
type="text"
17+
data-address="{&quot;field&quot;: &quot;{{$field['name']}}&quot;, &quot;full&quot;: {{isset($field['store_as_json']) && $field['store_as_json'] ? 'true' : 'false'}} }"
18+
name="{{ $field['name'] }}"
19+
value="{{ old($field['name']) ? old($field['name']) : (isset($field['value']) ? $field['value'] : (isset($field['default']) ? $field['default'] : '' )) }}"
20+
@include('crud::inc.field_attributes')
21+
>
22+
@endif
23+
@if(isset($field['suffix'])) <div class="input-group-addon">{!! $field['suffix'] !!}</div> @endif
24+
@if(isset($field['prefix']) || isset($field['suffix'])) </div> @endif
25+
26+
{{-- HINT --}}
27+
@if (isset($field['hint']))
28+
<p class="help-block">{!! $field['hint'] !!}</p>
29+
@endif
30+
</div>
31+
32+
{{-- Note: you can use to only load some CSS/JS once, even though there are multiple instances of it --}}
33+
34+
{{-- ########################################## --}}
35+
{{-- Extra CSS and JS for this particular field --}}
36+
{{-- If a field type is shown multiple times on a form, the CSS and JS will only be loaded once --}}
37+
@if ($crud->checkIfFieldIsFirstOfItsType($field, $fields))
38+
39+
{{-- FIELD CSS - will be loaded in the after_styles section --}}
40+
@push('crud_fields_styles')
41+
<style>
42+
.ap-input-icon.ap-icon-pin {
43+
right: 5px !important; }
44+
.ap-input-icon.ap-icon-clear {
45+
right: 10px !important; }
46+
</style>
47+
@endpush
48+
49+
{{-- FIELD JS - will be loaded in the after_scripts section --}}
50+
@push('crud_fields_scripts')
51+
<script src="https://cdn.jsdelivr.net/places.js/1/places.min.js"></script>
52+
<script>
53+
jQuery(document).ready(function($){
54+
window.AlgoliaPlaces = window.AlgoliaPlaces || {};
55+
56+
$('[data-address]').each(function(){
57+
58+
var $this = $(this),
59+
$addressConfig = $this.data('address'),
60+
$field = $('[name="'+$addressConfig.field+'"]'),
61+
$place = places({
62+
container: $this[0]
63+
});
64+
65+
if( $addressConfig.full ){
66+
67+
$place.on('change', function(e){
68+
var result = JSON.parse(JSON.stringify(e.suggestion));
69+
delete(result.highlight); delete(result.hit); delete(result.hitIndex);
70+
delete(result.rawAnswer); delete(result.query);
71+
$field.val( JSON.stringify(result) );
72+
});
73+
74+
var existingData = JSON.parse($field.val());
75+
$this.val(existingData.value);
76+
}
77+
78+
window.AlgoliaPlaces[ $addressConfig.field ] = $place;
79+
});
80+
});
81+
</script>
82+
@endpush
83+
84+
@endif
85+
{{-- End of Extra CSS and JS --}}
86+
{{-- ########################################## --}}

0 commit comments

Comments
 (0)