Created
November 3, 2019 17:55
-
-
Save JamesRagonesi/a334036695191735cb3d12bd74d55972 to your computer and use it in GitHub Desktop.
Reusable Forms - Model
This file contains 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 { Model } from "@vuex-orm/core"; | |
import { required, maxLength, minLength } from "vuelidate/lib/validators"; | |
export default class Comment extends Model { | |
static fields() { | |
return { | |
id: this.attr(null), | |
text: this.string(""), | |
}; | |
} | |
// Keep validations within the model | |
static get validations() { | |
return { | |
form: { | |
text: { required, maxLength: maxLength(24), minLength: minLength(6) }, | |
} | |
}; | |
} | |
// Call to send new POST request | |
toCreatePayload() { | |
return { | |
text: this.text, | |
}; | |
} | |
// Call to send new PUT request | |
toUpdatePayload() { | |
return { | |
...this.toCreatePayload(), | |
id: this.$id | |
}; | |
} | |
} | |
Comment.entity = "comments"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment