Skip to content

Commit a40e23c

Browse files
committed
add number prop to input field
1 parent 682c6ab commit a40e23c

File tree

2 files changed

+60
-7
lines changed

2 files changed

+60
-7
lines changed

dev/schema.js

+57-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ module.exports = {
135135
type: "input",
136136
inputType: "range",
137137
label: "Range",
138-
model: "age",
138+
model: "rank",
139+
min: 0,
140+
max: 10,
139141
styleClasses: "half-width"
140142
},
141143
{
@@ -272,11 +274,63 @@ module.exports = {
272274
rows: 4,
273275
validator: validators.string
274276
},
277+
{
278+
type: "text",
279+
label: "Field with buttons",
280+
model: "address.geo",
281+
disabled: false,
282+
get(model) {
283+
if (model && model.address && model.address.geo)
284+
return model.address.geo.latitude + ", " + model.address.geo.longitude;
285+
},
286+
set(model, val) {
287+
let values = val.split(",");
288+
if (!model.address)
289+
model.address = {};
290+
if (!model.address.geo)
291+
model.address.geo = {};
292+
if (values.length > 0 && values[0].trim() != "")
293+
model.address.geo.latitude = parseFloat(values[0].trim());
294+
else
295+
model.address.geo.latitude = 0
296+
if (values.length > 1 && values[1].trim() != "")
297+
model.address.geo.longitude = parseFloat(values[1].trim());
298+
else
299+
model.address.geo.longitude = 0
300+
},
301+
buttons: [{
302+
classes: "btn-location",
303+
label: "Current location",
304+
onclick: function(model) {
305+
if (navigator.geolocation) {
306+
navigator.geolocation.getCurrentPosition((pos) => {
307+
if (!model.address)
308+
model.address = {};
309+
if (!model.address.geo)
310+
model.address.geo = {};
311+
model.address.geo.latitude = pos.coords.latitude.toFixed(5);
312+
model.address.geo.longitude = pos.coords.longitude.toFixed(5);
313+
});
314+
} else {
315+
alert("Geolocation is not supported by this browser.");
316+
}
317+
}
318+
}, {
319+
classes: "btn-clear",
320+
label: "Clear",
321+
onclick: function(model) {
322+
model.address.geo = {
323+
latitude: 0,
324+
longitude: 0
325+
};
326+
}
327+
}]
328+
},
275329
{
276330
type: "staticMap",
277331
label: "Map",
278332
model: "address.geo",
279-
visible: true,
333+
visible: false,
280334
staticMapOptions: {
281335
lat: "latitude",
282336
lng: "longitude",
@@ -503,7 +557,7 @@ module.exports = {
503557
format: "YYYY-MM-DD"
504558
},
505559
onChanged(model, newVal, oldVal, field) {
506-
model.age = moment().year() - moment(newVal).year();
560+
//model.age = moment().year() - moment(newVal).year();
507561
}
508562
},
509563
{

src/fields/fieldInput.vue

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
input.form-control(
44
:type="schema.inputType",
55
v-model="value",
6+
number="schema.inputType == 'number'"
67
:disabled="disabled",
78

89
:accept="schema.accept",
@@ -59,12 +60,10 @@
5960
this.schema.inputType === "datetime" ||
6061
this.schema.inputType === "datetimelocal") {
6162
return new Date(value).getTime();
62-
}else{
63-
return value;
6463
}
65-
} else {
66-
return value;
6764
}
65+
66+
return value;
6867
}
6968
}
7069
};

0 commit comments

Comments
 (0)