Skip to content

Commit 4b5fc14

Browse files
authored
Merge pull request #39 from lionel-bijaoui/LB_pikaday
⭐ new field type: Pikaday
2 parents 1f22d80 + b0e3e96 commit 4b5fc14

File tree

4 files changed

+295
-5
lines changed

4 files changed

+295
-5
lines changed

dev/index.html

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,26 @@
1111
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.1.4/css/ion.rangeSlider.css">
1212
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.1.4/css/ion.rangeSlider.skinHTML5.css">
1313
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/noUiSlider/8.5.1/nouislider.min.css">
14+
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/pikaday/1.4.0/css/pikaday.min.css">
15+
1416

15-
1617
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.js"></script>
1718
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
18-
19+
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.3.0/lodash.min.js"></script>
20+
<!-- jQuery dependent -->
1921
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script>
2022
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>
2123
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
2224
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/spectrum/1.8.0/spectrum.js"></script>
2325
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.js"></script>
2426
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.1.4/js/ion.rangeSlider.js"></script>
27+
<!-- Vanilla libs -->
2528
<script type="text/javascript" src="https://rawgit.com/monterail/vue-multiselect/master/lib/vue-multiselect.min.js"></script>
29+
<script type="text/javascript" src="https://rawgit.com/nosir/cleave.js/master/dist/cleave.min.js"></script>
30+
<script type="text/javascript" src="https://nosir.github.io/cleave.js/lib/cleave-phone.i18n.js"></script>
2631
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/noUiSlider/8.5.1/nouislider.js"></script>
27-
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.3.0/lodash.min.js"></script>
32+
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pikaday/1.4.0/pikaday.min.js"></script>
33+
2834
</head>
2935
<body>
3036
<div class="container-fluid"></div>

dev/schema.js

+83-2
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,39 @@ module.exports = {
191191
styleClasses: "half-width"
192192
//validator: validators.regexp
193193
}, {
194+
type: "cleave",
195+
label: "Mobile (Cleave.js field)",
196+
model: "mobile",
197+
cleaveOptions: {
198+
// Credit Card
199+
creditCard: false,
200+
onCreditCardTypeChanged(type){
201+
console.log("onCreditCardTypeChanged", type);
202+
},
203+
// Phone
204+
phone: false,
205+
phoneRegionCode: 'AU',
206+
// Date
207+
date: false,
208+
datePattern: ['d', 'm', 'Y'],
209+
// Numerals
210+
numeral: false,
211+
numeralThousandsGroupStyle: 'thousand',
212+
numeralDecimalScale: 2,
213+
numeralDecimalMark: '.',
214+
// General
215+
blocks: [0, 2, 3, 4],
216+
delimiter: ' ',
217+
delimiters: ['(', ') ', '-', '-'],
218+
// prefix: '(',
219+
numericOnly: true,
220+
uppercase: false,
221+
lowercase: false
222+
},
223+
224+
styleClasses: "half-width",
225+
validator: validators.required
226+
}, {
194227
type: "masked",
195228
label: "Mobile (masked field)",
196229
model: "mobile",
@@ -255,9 +288,57 @@ module.exports = {
255288
model.age = moment().year() - moment(newVal).year();
256289
}
257290

258-
},
291+
}, {
292+
type: "pikaday",
293+
label: "DOB (pikaday field)",
294+
model: "dob",
295+
required: true,
296+
placeholder: "User's birth of date",
297+
min: moment("1900-01-01").toDate(),
298+
max: moment("2016-01-01").toDate(),
299+
validator: [
300+
validators.date
301+
],
302+
pikadayOptions: {
303+
bound: true,
304+
position: 'bottom left',
305+
reposition: true,
306+
// container: ,
307+
format: 'YYYY-MM-DD HH:mm:ss',
308+
// formatStrict: ,
309+
// defaultDate: ,
310+
// setDefaultDate: ,
311+
firstDay: 1,
312+
// minDate: ,
313+
// maxDate: ,
314+
disableWeekends: false,
315+
// disableDayFn: ,
316+
// yearRange: ,
317+
showWeekNumber: false,
318+
isRTL: false,
319+
i18n: {
320+
previousMonth : 'Previous Month',
321+
nextMonth : 'Next Month',
322+
months : ['January','February','March','April','May','June','July','August','September','October','November','December'],
323+
weekdays : ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
324+
weekdaysShort : ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
325+
},
326+
// yearSuffix: ,
327+
showMonthAfterYear: false,
328+
showDaysInNextAndPreviousMonths: false,
329+
// numberOfMonths: ,
330+
// mainCalendar: ,
331+
theme: null,
332+
// onSelect: ,
333+
// onOpen: ,
334+
// onClose: ,
335+
// onDraw: ,
336+
},
337+
onChanged(model, newVal, oldVal, field) {
338+
model.age = moment().year() - moment(newVal).year();
339+
}
259340

260-
{
341+
},{
261342
type: "dateTime",
262343
label: "DT",
263344
model: "dt",

src/fields/fieldCleave.vue

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<template lang="jade">
2+
input.form-control(type="text")
3+
</template>
4+
5+
<script>
6+
import abstractField from "./abstractField";
7+
import { defaults } from "lodash";
8+
9+
export default {
10+
mixins: [abstractField],
11+
12+
data() {
13+
return {
14+
cleave: null
15+
};
16+
},
17+
18+
watch: {
19+
/*model: {
20+
get(){
21+
if (window.Cleave) {
22+
console.log("get model", this.model);
23+
}
24+
},
25+
set(value) {
26+
if (window.Cleave) {
27+
console.log("set model", this.model, value);
28+
29+
}
30+
}
31+
}*/
32+
},
33+
34+
methods: {
35+
/*formatValueToField(){
36+
console.log(" 1 formatValueToField",this.cleave);
37+
if (this.cleave) {
38+
39+
return this.cleave.getRawValue();
40+
}else{
41+
console.log("fail")
42+
// this.cleave.element.value = "";
43+
return "";
44+
}
45+
},*/
46+
/*formatValueToModel(newValue){
47+
console.log(" 2 formatValueToModel");
48+
this.cleave.setRawValue(newValue);
49+
return newValue;
50+
}*/
51+
// onCreditCardTypeChanged(type){
52+
// let onCreditCardTypeChanged = this.schema.onCreditCardTypeChanged;
53+
// if (typeof(onNewTag) == "function") {
54+
// onNewTag(newTag, id, this.options, this.value);
55+
// }
56+
// }
57+
/*onChange(value) {
58+
console.log(value);
59+
if (value.length === 1) {
60+
// Single value
61+
this.value = parseFloat(value[0]);
62+
} else {
63+
// Array (range)
64+
this.value = [parseFloat(value[0]), parseFloat(value[1])];
65+
}
66+
}*/
67+
},
68+
69+
ready() {
70+
if (window.Cleave) {
71+
this.cleave = new Cleave(this.$el, defaults(this.schema.cleaveOptions || {}, {
72+
// Credit Card
73+
creditCard: false,
74+
// onCreditCardTypeChanged: onCreditCardTypeChanged.bind(this),
75+
// Phone
76+
phone: false,
77+
phoneRegionCode: 'AU',
78+
// Date
79+
date: false,
80+
datePattern: ['d', 'm', 'Y'],
81+
// Numerals
82+
numeral: false,
83+
numeralThousandsGroupStyle: 'thousand',
84+
numeralDecimalScale: 2,
85+
numeralDecimalMark: '.',
86+
// General
87+
blocks: [],
88+
delimiter: ' ',
89+
prefix: null,
90+
numericOnly: false,
91+
uppercase: false,
92+
lowercase: false
93+
}));
94+
} else {
95+
console.warn("Cleave is missing. Please download from https://github.com/nosir/cleave.js/ and load the script in the HTML head section!");
96+
}
97+
}
98+
};
99+
</script>
100+
101+
<style lang="sass">
102+
.vue-form-generator .field-cleave {}
103+
</style>

src/fields/fieldPikaday.vue

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<template lang="jade">
2+
input.form-control(type="text")
3+
</template>
4+
5+
<script>
6+
import abstractField from "./abstractField";
7+
import moment from "moment";
8+
import { defaults } from "lodash";
9+
10+
let inputFormat = "YYYY-MM-DD HH:mm:ss";
11+
12+
export default {
13+
mixins: [ abstractField ],
14+
data(){
15+
return {picker: null};
16+
},
17+
18+
methods: {
19+
20+
getDateFormat() {
21+
if (this.schema.pikadayOptions && this.schema.pikadayOptions.format)
22+
return this.schema.pikadayOptions.format;
23+
else
24+
return inputFormat;
25+
},
26+
27+
formatValueToField(value) {
28+
if (value != null)
29+
return moment(value, this.schema.format).format(this.getDateFormat());
30+
31+
return value;
32+
},
33+
34+
formatValueToModel(value) {
35+
if (value != null) {
36+
let m = moment(value, this.getDateFormat());
37+
if (this.schema.format)
38+
value = m.format(this.schema.format);
39+
else
40+
value = m.toDate().valueOf();
41+
}
42+
console.log(this.value);
43+
// this.value = value;
44+
return value;
45+
}
46+
47+
},
48+
49+
ready() {
50+
if (window.Pikaday){
51+
this.picker = new Pikaday(defaults(this.schema.pikadayOptions || {}, {
52+
field: this.$el, // bind the datepicker to a form field
53+
// trigger: , // use a different element to trigger opening the datepicker, see [trigger example][] (default to `field`)
54+
bound: true, // automatically show/hide the datepicker on `field` focus (default `true` if `field` is set)
55+
position: 'bottom left', // preferred position of the datepicker relative to the form field, e.g.: `top right`, `bottom right` **Note:** automatic adjustment may occur to avoid datepicker from being displayed outside the viewport, see [positions example][] (default to 'bottom left')
56+
reposition: true, // can be set to false to not reposition datepicker within the viewport, forcing it to take the configured `position` (default: true)
57+
// container: , // DOM node to render calendar into, see [container example][] (default: undefined)
58+
// format: , // the default output format for `.toString()` and `field` value (requires [Moment.js][moment] for custom formatting)
59+
// formatStrict: , // the default flag for moment's strict date parsing (requires [Moment.js][moment] for custom formatting)
60+
// defaultDate: , // the initial date to view when first opened
61+
// setDefaultDate: , // make the `defaultDate` the initial selected value
62+
firstDay: 1, // first day of the week (0: Sunday, 1: Monday, etc)
63+
// minDate: , // the minimum/earliest date that can be selected (this should be a native Date object - e.g. `new Date()` or `moment().toDate()`)
64+
// maxDate: , // the maximum/latest date that can be selected (this should be a native Date object - e.g. `new Date()` or `moment().toDate()`)
65+
disableWeekends: false, // disallow selection of Saturdays or Sundays
66+
// disableDayFn: , // callback function that gets passed a Date object for each day in view. Should return true to disable selection of that day.
67+
// yearRange: , // number of years either side (e.g. `10`) or array of upper/lower range (e.g. `[1900,2015]`)
68+
showWeekNumber: false, // show the ISO week number at the head of the row (default `false`)
69+
isRTL: false, // reverse the calendar for right-to-left languages
70+
i18n: {
71+
previousMonth : 'Previous Month',
72+
nextMonth : 'Next Month',
73+
months : ['January','February','March','April','May','June','July','August','September','October','November','December'],
74+
weekdays : ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
75+
weekdaysShort : ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
76+
}, // language defaults for month and weekday names (see internationalization below)
77+
// yearSuffix: , // additional text to append to the year in the title
78+
showMonthAfterYear: false, // render the month after year in the title (default `false`)
79+
showDaysInNextAndPreviousMonths: false, // render days of the calendar grid that fall in the next or previous months to the current month instead of rendering an empty table cell (default: false)
80+
// numberOfMonths: , // number of visible calendars
81+
// mainCalendar: , // when `numberOfMonths` is used, this will help you to choose where the main calendar will be (default `left`, can be set to `right`). Only used for the first display or when a selected date is not already visible
82+
theme: null, // define a classname that can be used as a hook for styling different themes, see [theme example][] (default `null`)
83+
// onSelect: , // callback function for when a date is selected
84+
// onOpen: , // callback function for when the picker becomes visible
85+
// onClose: , // callback function for when the picker is hidden
86+
// onDraw: , // callback function for when the picker draws a new month
87+
}));
88+
}
89+
// this.slider.noUiSlider.on("change", this.onChange.bind(this));
90+
else{
91+
console.warn("Pikaday is missing. Please download from https://github.com/dbushell/Pikaday/ and load the script and CSS in the HTML head section!");
92+
}
93+
94+
}
95+
};
96+
</script>
97+
98+
99+
<style lang="sass">
100+
</style>

0 commit comments

Comments
 (0)