Skip to content

Commit 547ea2e

Browse files
committed
Implement #199
1 parent a6aaf1b commit 547ea2e

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

dev/full/app.vue

+16
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,22 @@
195195
196196
modelUpdated(newVal, schema) {
197197
console.log("main model has updated", newVal, schema);
198+
},
199+
200+
201+
getLocation(model) {
202+
if (navigator.geolocation) {
203+
navigator.geolocation.getCurrentPosition((pos) => {
204+
if (!model.address)
205+
model.address = {};
206+
if (!model.address.geo)
207+
model.address.geo = {};
208+
model.address.geo.latitude = pos.coords.latitude.toFixed(5);
209+
model.address.geo.longitude = pos.coords.longitude.toFixed(5);
210+
});
211+
} else {
212+
alert("Geolocation is not supported by this browser.");
213+
}
198214
}
199215
200216

dev/full/schema.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -351,18 +351,7 @@ module.exports = {
351351
classes: "btn-location",
352352
label: "Current location",
353353
onclick: function(model) {
354-
if (navigator.geolocation) {
355-
navigator.geolocation.getCurrentPosition((pos) => {
356-
if (!model.address)
357-
model.address = {};
358-
if (!model.address.geo)
359-
model.address.geo = {};
360-
model.address.geo.latitude = pos.coords.latitude.toFixed(5);
361-
model.address.geo.longitude = pos.coords.longitude.toFixed(5);
362-
});
363-
} else {
364-
alert("Geolocation is not supported by this browser.");
365-
}
354+
return this.$parent.getLocation(model);
366355
}
367356
}, {
368357
classes: "btn-clear",

src/formGenerator.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ div
1111
.field-wrap
1212
component(:is='getFieldType(field)', :disabled='fieldDisabled(field)', :model='model', :schema.sync='field', @model-updated='modelUpdated', @validated="onFieldValidated")
1313
.buttons(v-if='buttonVisibility(field)')
14-
button(v-for='btn in field.buttons', @click='btn.onclick(model, field)', :class='btn.classes') {{ btn.label }}
14+
button(v-for='btn in field.buttons', @click='buttonClickHandler(btn, field)', :class='btn.classes') {{ btn.label }}
1515
.hint(v-if='field.hint') {{ field.hint }}
1616
.errors.help-block(v-if='fieldErrors(field).length > 0')
1717
span(v-for='(error, index) in fieldErrors(field)', track-by='index') {{ error }}
@@ -227,6 +227,10 @@ div
227227
return field.featured;
228228
},
229229
230+
buttonClickHandler(btn, field) {
231+
return btn.onclick.call(this, this.model, field, this);
232+
},
233+
230234
// Child field executed validation
231235
onFieldValidated(res, errors, field) {
232236
// Remove old errors for this field

0 commit comments

Comments
 (0)