Skip to content

Instantly share code, notes, and snippets.

@onefriendaday
Created June 14, 2019 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onefriendaday/2327b23465b493468872feca324a2c43 to your computer and use it in GitHub Desktop.
Save onefriendaday/2327b23465b493468872feca324a2c43 to your computer and use it in GitHub Desktop.
Url
const Fieldtype = {
template: `
<div v-if="model.urlList">
<div class="uk-flex uk-flex-middle" v-for="(locale, key) in options" :key="locale">
<div v-html="locale" />
<input type="text" class="form-control" id="basic-url" aria-describedby="basic-addon3" :value="model.urlList[key]" @input="validate($event, key)">
<div>/</div>
<div v-if="showError[key]">!!! Url invalid</div>
</div>
</div>
`,
mixins: [window.Storyblok.plugin],
data() {
return {
showError: {}
}
},
methods: {
_extend(target) {
for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target;
},
initWith() {
return {
plugin: 'rebtel-com-locale-urls',
urlList: {},
computedUrlList: {}
}
},
pluginCreated() {
},
validate(e, key) {
let inputValue = e.target.value
if (!inputValue) {
delete this.model.urlList[key]
} else {
if (inputValue.indexOf(' ') > -1) {
this.showError[key] = true
this.showError = this._extend({}, this.showError)
} else {
this.showError[key] = false
let route = `${this.options[key]}${inputValue}/`.replace('//', '/')
this.model.computedUrlList[key] = route
}
this.model.urlList[key] = inputValue
this.$emit('changed-model', this.model);
}
}
},
watch: {
'model': {
handler: function(value) {
this.$emit('changed-model', value);
},
deep: true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment