Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export const formMixin = {
- data () {
- return {
- isStoring: false,
- serverValidationErrors: {},
- responseMessage: null,
- responseStatus: null,
- formFields: {},
- }
- },
- created() {
- },
- methods: {
- resetFlags(){
- for (let key of Object.keys(this.fields)){
- this.$validator.flag(key, {
- "untouched": true,
- "touched": false,
- "dirty": false,
- "valid": true,
- "invalid": false,
- "validated": false
- });
- }
- },
- beforeStoreHandler(){
- this.serverValidationErrors = {};
- this.serverError = null;
- this.isStoring = true;
- this.responseMessage = null;
- this.responseStatus = null;
- },
- storeErrorHandler(error){
- this.isStoring = false;
- this.responseStatus = 'error';
- if (error.response && error.response.data && error.response.data.errors) {
- this.serverValidationErrors = error.response.data.errors;
- }
- if ((error.response && error.response.data && error.response.data.message) || error.message) {
- this.responseMessage = error.response.data.message || error.message;
- }
- },
- storeSuccessHandler(response){
- this.isStoring = false;
- this.responseStatus = 'success';
- // this.formFields = {};
- if (response && response.message) {
- this.responseMessage = response.message;
- }
- // if (response && response.redirect) {
- // window.location.replace(response.redirect);
- // }
- },
- getErrors(name, scope = null){
- let errors = [];
- if (this.errors.has(`${scope ? `${scope}.` : ''}${name}`)){
- errors.push(this.errors.first(`${scope ? `${scope}.` : ''}${name}`));
- }
- if (this.serverValidationErrors[name]){
- for (let index in this.serverValidationErrors[name]){
- errors.push(this.serverValidationErrors[name][index]);
- }
- }
- return errors;
- },
- resetForm() {
- this.$validator.reset();
- this.serverValidationErrors = {};
- this.serverError = null;
- this.responseMessage = null;
- this.responseStatus = null;
- this.formFields = {};
- }
- },
- };
Add Comment
Please, Sign In to add comment