Skip to content

Commit

Permalink
add number prop to input field
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Nov 3, 2016
1 parent 682c6ab commit a40e23c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
60 changes: 57 additions & 3 deletions dev/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ module.exports = {
type: "input",
inputType: "range",
label: "Range",
model: "age",
model: "rank",
min: 0,
max: 10,
styleClasses: "half-width"
},
{
Expand Down Expand Up @@ -272,11 +274,63 @@ module.exports = {
rows: 4,
validator: validators.string
},
{
type: "text",
label: "Field with buttons",
model: "address.geo",
disabled: false,
get(model) {
if (model && model.address && model.address.geo)
return model.address.geo.latitude + ", " + model.address.geo.longitude;
},
set(model, val) {
let values = val.split(",");
if (!model.address)
model.address = {};
if (!model.address.geo)
model.address.geo = {};
if (values.length > 0 && values[0].trim() != "")
model.address.geo.latitude = parseFloat(values[0].trim());
else
model.address.geo.latitude = 0
if (values.length > 1 && values[1].trim() != "")
model.address.geo.longitude = parseFloat(values[1].trim());
else
model.address.geo.longitude = 0
},
buttons: [{
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.");
}
}
}, {
classes: "btn-clear",
label: "Clear",
onclick: function(model) {
model.address.geo = {
latitude: 0,
longitude: 0
};
}
}]
},
{
type: "staticMap",
label: "Map",
model: "address.geo",
visible: true,
visible: false,
staticMapOptions: {
lat: "latitude",
lng: "longitude",
Expand Down Expand Up @@ -503,7 +557,7 @@ module.exports = {
format: "YYYY-MM-DD"
},
onChanged(model, newVal, oldVal, field) {
model.age = moment().year() - moment(newVal).year();
//model.age = moment().year() - moment(newVal).year();
}
},
{
Expand Down
7 changes: 3 additions & 4 deletions src/fields/fieldInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
input.form-control(
:type="schema.inputType",
v-model="value",
number="schema.inputType == 'number'"
:disabled="disabled",

:accept="schema.accept",
Expand Down Expand Up @@ -59,12 +60,10 @@
this.schema.inputType === "datetime" ||
this.schema.inputType === "datetimelocal") {
return new Date(value).getTime();
}else{
return value;
}
} else {
return value;
}
return value;
}
}
};
Expand Down

0 comments on commit a40e23c

Please sign in to comment.