Skip to content

Instantly share code, notes, and snippets.

@onefriendaday
Created January 28, 2019 16:31
Show Gist options
  • Save onefriendaday/26af9ad4508a60670a333890c687cf86 to your computer and use it in GitHub Desktop.
Save onefriendaday/26af9ad4508a60670a333890c687cf86 to your computer and use it in GitHub Desktop.
Storyblok fieldtype with field validation
const Fieldtype = {
mixins: [window.Storyblok.plugin],
template: `<div>
<input class="uk-width-1-1" @input="validate" v-model="proxyModel.example" />
<div v-if="!valid">Please fill out this field</div>
</div>`,
data() {
return {
proxyModel: {},
valid: false
}
},
methods: {
initWith() {
return {
}
},
validate() {
if (this.proxyModel.example.length > 3) {
this.valid = true
this.$emit('changed-model', this.proxyModel)
} else {
this.valid = false
this.$emit('changed-model', {})
}
},
pluginCreated() {
if (this.model !== {}) {
this.proxyModel = this.model
}
console.log('plugin:created')
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment