Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. import { ErrorBag } from '../utils'
  2.  
  3. export default {
  4. inject: ['form'],
  5.  
  6. props: {
  7. value: { required: true },
  8. title: { type: String, default: null },
  9. subtitle: { type: String, default: null },
  10. name: { type: String, default: null },
  11. inputName: { type: String, default: null },
  12. errors: {
  13. validator (errors) {
  14. return !errors || errors instanceof ErrorBag
  15. },
  16.  
  17. default: null
  18. },
  19. inputClass: String,
  20. placeholder: String,
  21. autofill: [String, Boolean],
  22. autocomplete: [String, Boolean],
  23. autofocus: [Boolean],
  24. min: {},
  25. max: {}
  26. },
  27.  
  28. data: () => ({
  29. expression: null,
  30. required: null
  31. }),
  32.  
  33. computed: {
  34.  
  35. id () {
  36. return `text${this._uid}`
  37. },
  38.  
  39. nameKey () {
  40. const inputName = this.inputName
  41. const expression = this.expression
  42.  
  43. if (inputName) return inputName
  44.  
  45. return expression
  46. },
  47.  
  48. feedback () {
  49. const errors = this.errors
  50. const form = this.form
  51. const name = this.nameKey
  52.  
  53. if (errors) {
  54. return errors.get(name)
  55. }
  56.  
  57. if (form && form.errors) {
  58. return form.errors.get(name)
  59. }
  60.  
  61. return null
  62. }
  63. },
  64.  
  65. methods: {
  66. /**
  67. * Mirror attributes from root element.
  68. *
  69. * @return {void}
  70. */
  71. updateAttributes () {
  72. if (!this.$vnode || !this.$vnode.data || !this.$vnode.data.attrs) return
  73.  
  74. this.required = this.$vnode.data.attrs.hasOwnProperty('required')
  75. }
  76. },
  77.  
  78. mounted () {
  79. const model = this.$vnode.data.model
  80.  
  81. if (model) {
  82. this.expression = model.expression.split('.').pop()
  83. }
  84.  
  85. this.updateAttributes()
  86.  
  87. if (this.autofocus !== false) {
  88. this.$nextTick(() => {
  89. const el = this.$el.querySelector('[autofocus]')
  90. if (el) el.focus()
  91. })
  92. }
  93. },
  94.  
  95. beforeUpdate () {
  96. this.updateAttributes()
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement