Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. const Fieldtype = {
  2. template: `
  3. <div v-if="model.urlList">
  4. <div class="uk-flex uk-flex-middle" v-for="(locale, key) in options" :key="locale">
  5. <div v-html="locale" />
  6. <input type="text" class="form-control" id="basic-url" aria-describedby="basic-addon3" :value="model.urlList[key]" @input="validate($event, key)">
  7. <div>/</div>
  8. <div v-if="showError[key]">!!! Url invalid</div>
  9. </div>
  10. </div>
  11. `,
  12. mixins: [window.Storyblok.plugin],
  13. data() {
  14. return {
  15. showError: {}
  16. }
  17. },
  18. methods: {
  19. _extend(target) {
  20. 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;
  21. },
  22. initWith() {
  23. return {
  24. plugin: 'rebtel-com-locale-urls',
  25. urlList: {},
  26. computedUrlList: {}
  27. }
  28. },
  29. pluginCreated() {
  30.  
  31. },
  32. validate(e, key) {
  33. let inputValue = e.target.value
  34. if (!inputValue) {
  35. delete this.model.urlList[key]
  36. } else {
  37. if (inputValue.indexOf(' ') > -1) {
  38. this.showError[key] = true
  39. this.showError = this._extend({}, this.showError)
  40. } else {
  41. this.showError[key] = false
  42. let route = `${this.options[key]}${inputValue}/`.replace('//', '/')
  43. this.model.computedUrlList[key] = route
  44. }
  45. this.model.urlList[key] = inputValue
  46. this.$emit('changed-model', this.model);
  47. }
  48. }
  49. },
  50. watch: {
  51. 'model': {
  52. handler: function(value) {
  53. this.$emit('changed-model', value);
  54. },
  55. deep: true
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement