/
form.js
74 lines (64 loc) · 1.65 KB
/
form.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var form = {
data () {
return {
inputValue: '',
inputVisible: false,
userTags: []
}
},
methods: {
// Form Submission
submitForm (formName) {
this.$refs[formName].validate((valid, err) => {
if (valid) {
this.submit()
} else {
this.$notify.error({
title: 'Error',
message: 'Please check the form, there appears to be an issue with the information you provided'
})
// In the event that the validation fails in newGigData all sections should be opened so a user can easily view the issue
if (formName === 'newGigData') {
this.activeNames = ['1', '2', '3', '4', '5']
}
}
})
},
// Form Reset
resetForm (formName) {
this.$refs[formName].resetFields()
},
// Tag Methods
handleClose (userTag) {
this.userTags.splice(this.userTags.indexOf(userTag), 1)
},
showInput () {
this.inputVisible = true
this.$nextTick(_ => {
this.$refs.saveTagInput.$refs.input.focus()
})
},
handleInputConfirm () {
let inputValue = this.inputValue
if (inputValue) {
this.userTags.push(inputValue)
}
this.inputVisible = false
this.inputValue = ''
},
saveDraft (type, data) {
window.localStorage.setItem(type, JSON.stringify(data))
},
getDrafts (type) {
if (window.localStorage.getItem(type)) {
return JSON.parse(window.localStorage.getItem(type))
} else {
return ''
}
},
removeDraft (type) {
localStorage.removeItem(type)
}
}
}
export default form