Created
April 15, 2017 17:33
-
-
Save BrockReece/f937805d07a52be491246dd27032c5a1 to your computer and use it in GitHub Desktop.
Vue form analytics mixin
This file contains hidden or 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
import { mapActions } from 'vuex' | |
export default { | |
methods: { | |
...mapActions([ | |
'updateInputFocus', | |
]), | |
lastInputFocus(e) { | |
if (!e.srcElement.name) return | |
this.updateInputFocus(e.srcElement.name) | |
}, | |
setFocusListner() { | |
this.$nextTick(() => { | |
this.$el.querySelectorAll('input').forEach((input) => { | |
input.addEventListener('focus', this.lastInputFocus) | |
}) | |
this.$el.querySelectorAll('textarea').forEach((input) => { | |
input.addEventListener('focus', this.lastInputFocus) | |
}) | |
}) | |
}, | |
sendAnalytics() { | |
this.$http.post(this.analyticsEndpoint, { | |
type: this.analyticsType, | |
data: { | |
...this.analytics, | |
errors: this.errors.map(error => ({ text: error })), | |
}, | |
}) | |
}, | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment