Created
January 28, 2019 16:31
-
-
Save onefriendaday/26af9ad4508a60670a333890c687cf86 to your computer and use it in GitHub Desktop.
Storyblok fieldtype with field validation
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" @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