Created
November 29, 2019 03:47
-
-
Save mattquest/2b8ad601f8f42b643302c765d4eac678 to your computer and use it in GitHub Desktop.
Javascript form class for use on Laravel frontend.
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
class Form { | |
constructor(url, fields) { | |
this.url = url | |
this.originalFields = { ...fields } | |
this.fields = fields | |
this.errors = {} | |
} | |
async post() { | |
let result = null | |
result = axios.post(this.url, this.fields) | |
result.catch(e => { | |
this.errors = { ...e.response.data.errors } | |
}) | |
return result | |
} | |
resetStatus() { | |
this.errors = {} | |
} | |
reset() { | |
this.resetStatus() | |
this.fields = { ...this.originalFields } | |
} | |
} | |
export default Form |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment