Created
April 26, 2019 14:07
-
-
Save onefriendaday/71f183a7e8f0d671aad5e57ee1799e2d to your computer and use it in GitHub Desktop.
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
const Fieldtype = { | |
mixins: [window.Storyblok.plugin], | |
template: ` | |
<div> | |
<input | |
class="uk-width-1-1" | |
type="number" | |
@input="validate" | |
:step="options.step || 1" | |
ref="input" | |
/> | |
</div> | |
`, | |
methods: { | |
initWith() { | |
return { | |
plugin: 'number-restricted', | |
value: null | |
} | |
}, | |
validate(e) { | |
let val = parseInt(e.target.value) | |
let max = parseInt(this.options.max) | |
if (val > parseInt(this.options.max)) { | |
val = parseInt(this.options.max) | |
} | |
if (val < parseInt(this.options.min)) { | |
val = parseInt(this.options.min) | |
} | |
this.$refs.input.value = val | |
this.model.value = val | |
}, | |
pluginCreated() { | |
this.$nextTick(() => { | |
if (this.model.value === null) { | |
this.model.value = this.options.default || '4' | |
this.$refs.input.value = this.model.value | |
} | |
}) | |
} | |
}, | |
watch: { | |
model: { | |
handler (model) { | |
this.$emit('changed-model', model) | |
}, | |
deep: true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment