Skip to content

Commit

Permalink
Implement #199
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed May 18, 2017
1 parent a6aaf1b commit 547ea2e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
16 changes: 16 additions & 0 deletions dev/full/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@
modelUpdated(newVal, schema) {
console.log("main model has updated", newVal, schema);
},
getLocation(model) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((pos) => {
if (!model.address)
model.address = {};
if (!model.address.geo)
model.address.geo = {};
model.address.geo.latitude = pos.coords.latitude.toFixed(5);
model.address.geo.longitude = pos.coords.longitude.toFixed(5);
});
} else {
alert("Geolocation is not supported by this browser.");
}
}
Expand Down
13 changes: 1 addition & 12 deletions dev/full/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,18 +351,7 @@ module.exports = {
classes: "btn-location",
label: "Current location",
onclick: function(model) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((pos) => {
if (!model.address)
model.address = {};
if (!model.address.geo)
model.address.geo = {};
model.address.geo.latitude = pos.coords.latitude.toFixed(5);
model.address.geo.longitude = pos.coords.longitude.toFixed(5);
});
} else {
alert("Geolocation is not supported by this browser.");
}
return this.$parent.getLocation(model);
}
}, {
classes: "btn-clear",
Expand Down
6 changes: 5 additions & 1 deletion src/formGenerator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ div
.field-wrap
component(:is='getFieldType(field)', :disabled='fieldDisabled(field)', :model='model', :schema.sync='field', @model-updated='modelUpdated', @validated="onFieldValidated")
.buttons(v-if='buttonVisibility(field)')
button(v-for='btn in field.buttons', @click='btn.onclick(model, field)', :class='btn.classes') {{ btn.label }}
button(v-for='btn in field.buttons', @click='buttonClickHandler(btn, field)', :class='btn.classes') {{ btn.label }}
.hint(v-if='field.hint') {{ field.hint }}
.errors.help-block(v-if='fieldErrors(field).length > 0')
span(v-for='(error, index) in fieldErrors(field)', track-by='index') {{ error }}
Expand Down Expand Up @@ -227,6 +227,10 @@ div
return field.featured;
},
buttonClickHandler(btn, field) {
return btn.onclick.call(this, this.model, field, this);
},
// Child field executed validation
onFieldValidated(res, errors, field) {
// Remove old errors for this field
Expand Down

0 comments on commit 547ea2e

Please sign in to comment.