Blame view
src/components/widgets/form/ContactForm.vue
5.83 KB
ade01719f
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
<template> <v-card ref="form"> <v-card-text> <v-text-field label="Full Name" placeholder="John Doe" v-model="name" required ref="name" :rules="[() => !!name || 'This field is required']" :error-messages="errorMessages" ></v-text-field> <v-text-field label="Address Line" placeholder="Snowy Rock Pl" :rules="[ () => !!address || 'This field is required', () => !!address && address.length <= 25 || 'Address must be less than 25 characters', addressCheck ]" v-model="address" ref="address" counter="25" required ></v-text-field> <v-text-field label="City" placeholder="El Paso" :rules="[() => !!city || 'This field is required', addressCheck]" v-model="city" ref="city" required ></v-text-field> <v-text-field label="State/Province/Region" v-model="state" :rules="[() => !!state || 'This field is required']" required ref="state" placeholder="TX" ></v-text-field> <v-text-field label="ZIP / Postal Code" required :rules="[() => !!zip || 'This field is required']" v-model="zip" ref="zip" placeholder="79938" ></v-text-field> <v-select autocomplete label="Country" placeholder="Select..." :rules="[() => !!country || 'This field is required']" :items="countries" v-model="country" ref="country" required ></v-select> </v-card-text> <v-divider class="mt-5"></v-divider> <v-card-actions> <v-btn flat>Cancel</v-btn> <v-spacer></v-spacer> <v-slide-x-reverse-transition> <v-tooltip left v-if="formHasErrors" > <v-btn icon @click="resetForm" slot="activator" class="my-0" > <v-icon>refresh</v-icon> </v-btn> <span>Refresh form</span> </v-tooltip> </v-slide-x-reverse-transition> <v-btn color="primary" flat @click="submit">Submit</v-btn> </v-card-actions> </v-card> </template> <script> export default { data: () => ({ countries: ['Afghanistan', 'Albania', 'Algeria', 'Andorra', 'Angola', 'Anguilla', 'Antigua & Barbuda', 'Argentina', 'Armenia', 'Aruba', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia & Herzegovina', 'Botswana', 'Brazil', 'British Virgin Islands', 'Brunei', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', 'Cape Verde', 'Cayman Islands', 'Chad', 'Chile', 'China', 'Colombia', 'Congo', 'Cook Islands', 'Costa Rica', 'Cote D Ivoire', 'Croatia', 'Cruise Ship', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Estonia', 'Ethiopia', 'Falkland Islands', 'Faroe Islands', 'Fiji', 'Finland', 'France', 'French Polynesia', 'French West Indies', 'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guam', 'Guatemala', 'Guernsey', 'Guinea', 'Guinea Bissau', 'Guyana', 'Haiti', 'Honduras', 'Hong Kong', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran', 'Iraq', 'Ireland', 'Isle of Man', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jersey', 'Jordan', 'Kazakhstan', 'Kenya', 'Kuwait', 'Kyrgyz Republic', 'Laos', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Macau', 'Macedonia', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Mauritania', 'Mauritius', 'Mexico', 'Moldova', 'Monaco', 'Mongolia', 'Montenegro', 'Montserrat', 'Morocco', 'Mozambique', 'Namibia', 'Nepal', 'Netherlands', 'Netherlands Antilles', 'New Caledonia', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Norway', 'Oman', 'Pakistan', 'Palestine', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Reunion', 'Romania', 'Russia', 'Rwanda', 'Saint Pierre & Miquelon', 'Samoa', 'San Marino', 'Satellite', 'Saudi Arabia', 'Senegal', 'Serbia', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia', 'South Africa', 'South Korea', 'Spain', 'Sri Lanka', 'St Kitts & Nevis', 'St Lucia', 'St Vincent', 'St. Lucia', 'Sudan', 'Suriname', 'Swaziland', 'Sweden', 'Switzerland', 'Syria', 'Taiwan', 'Tajikistan', 'Tanzania', 'Thailand', "Timor L'Este", 'Togo', 'Tonga', 'Trinidad & Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Turks & Caicos', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', 'Uruguay', 'Uzbekistan', 'Venezuela', 'Vietnam', 'Virgin Islands (US)', 'Yemen', 'Zambia', 'Zimbabwe'], errorMessages: [], name: null, address: null, city: null, state: null, zip: null, country: null, formHasErrors: false }), computed: { form () { return { name: this.name, address: this.address, city: this.city, state: this.state, zip: this.zip, country: this.country }; } }, watch: { name () { this.errorMessages = []; } }, methods: { addressCheck () { this.errorMessages = this.address && !this.name ? ['Hey! I\'m required'] : []; return true; }, resetForm () { this.errorMessages = []; this.formHasErrors = false; Object.keys(this.form).forEach(f => { this.$refs[f].reset(); }); }, submit () { this.formHasErrors = false; Object.keys(this.form).forEach(f => { if (!this.form[f]) this.formHasErrors = true; this.$refs[f].validate(true); }); } } }; </script> |