Last active
November 8, 2017 08:10
-
-
Save AndresCL/2e45360643a1858883616d349e0a9171 to your computer and use it in GitHub Desktop.
Using mariomka/vue-datetime as component for Vue-Formly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue' | |
import App from './App.vue' | |
import VueFormly from 'vue-formly' | |
// Adding it to VueFormly | |
import datepicker from "./Datepicker.vue" | |
VueFormly.addType('datepicker', datepicker); | |
// Use VueFormly globally | |
Vue.use(VueFormly) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<form v-on:submit="save()"> | |
<formly-form :form="form" :model="model" :fields="fields"></formly-form> | |
</form> | |
</template> | |
<script> | |
import modal from 'vue-strap/src/Modal' | |
export default { | |
name: 'calendar', | |
data () { | |
return { | |
form: {}, | |
model: { | |
startDate: '', | |
}, | |
fields: [ | |
{ | |
required: true, | |
key: 'startDate', | |
type: 'datepicker', | |
templateOptions: { | |
text: 'Start Date' | |
} | |
} | |
] | |
} | |
} | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="form-group formly-datepicker" :class="[ to.inputType, {'formly-has-value': model[field.key], 'formly-has-focus': form[field.key].$active, 'has-error': hasError}]"> | |
<label>{{field.templateOptions.text}}</label> | |
<datetime v-model="model[field.key]" | |
placeholder="Pick a date" | |
type="datetime" | |
input-format="DD-MM-YYYY h:mm:ss" | |
monday-first | |
auto-continue></datetime> | |
<error-display :form="form" :field="field.key"></error-display> | |
</div> | |
</template> | |
<script> | |
import Vue from 'vue' | |
import baseField from 'vue-formly-bootstrap/src/fields/baseField'; | |
import Datetime from 'vue-datetime'; | |
Vue.use(Datetime); | |
export default { | |
mixins: [baseField] | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Register the component locally feels better for this use case.