Skip to content

Instantly share code, notes, and snippets.

@tuanna-hsp
Created September 30, 2021 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuanna-hsp/5ebd0c3f2b8498a5a640fba800baa196 to your computer and use it in GitHub Desktop.
Save tuanna-hsp/5ebd0c3f2b8498a5a640fba800baa196 to your computer and use it in GitHub Desktop.
<script lang="ts">
import Vue, { PropType } from "vue";
import { requiredIf } from "vuelidate/lib/validators";
export default Vue.extend({
validations() {
const form: { [rule: string]: any } = {};
this.allAttributes.forEach(attr => {
form[attr] = {
required: requiredIf(function(this: any): boolean {
return this.isAttributeRequired(attr);
}),
};
});
return { form };
},
methods: {
isAttributeRequired(attr: string): boolean {
return this.requiredFields?.includes(attr);
},
},
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment