Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <v-container px-5>
  3.       <v-layout row wrap>
  4.           <v-flex xs12 sm6 offset-sm3>
  5.               <h4 class="success--text">Create a new Meetup</h4>
  6.           </v-flex>
  7.       </v-layout>
  8.       <v-form lazy-validation ref="form">
  9.       <v-layout row wrap>
  10.           <v-flex xs12 sm6 offset-sm3>
  11.               <v-text-field
  12.               name='title'
  13.               id='title'
  14.               label='Title'
  15.               required
  16.               v-model="title"
  17.               ></v-text-field>
  18.           </v-flex>
  19.       </v-layout>
  20.             <v-layout row wrap>
  21.           <v-flex xs12 sm6 offset-sm3>
  22.               <v-text-field
  23.               name='location'
  24.               id='location'
  25.               label='Location'
  26.               :rules='nameRules'
  27.               v-model="location"
  28.               required
  29.               ></v-text-field>
  30.           </v-flex>
  31.       </v-layout>
  32.             <v-layout row wrap>
  33.           <v-flex xs12 sm6 offset-sm3>
  34.               <!-- <v-text-field
  35.               name='imageUrl'
  36.               id='image-url'
  37.               label='Image URL'
  38.               v-model="imageUrl"
  39.               :rules="emailRules"  
  40.               required
  41.               ></v-text-field> -->
  42.             <v-file-input
  43.             show-size counter
  44.             prepend-icon="mdi-camera"
  45.             label="File input">
  46.             </v-file-input>
  47.           </v-flex>
  48.       </v-layout>
  49.        <v-layout row wrap>
  50.           <v-flex xs12 sm6 offset-sm3>
  51.          <img :src='imageUrl' height="150">
  52.           </v-flex>
  53.       </v-layout>
  54.             <v-layout row wrap>
  55.           <v-flex xs12 sm6 offset-sm3>
  56.               <v-textarea
  57.               name='description'
  58.               id='ddescription'
  59.               label='Description'
  60.               v-model="description"
  61.                persistent-hint
  62.             outlined
  63.               counter
  64.               maxlength="200"
  65.               required
  66.               ></v-textarea>
  67.           </v-flex>
  68.       </v-layout>
  69.              <v-layout row wrap mb-5>
  70.           <v-flex xs12 sm6 offset-sm3>
  71.          <h5 >Pick a date and time</h5>
  72.           </v-flex>
  73.       </v-layout>
  74.              <v-layout row wrap px-4>
  75.           <v-flex xs12 sm6 class="text-sm-right" px-3 mb-5>
  76.          <v-date-picker v-model="date"></v-date-picker>
  77.           </v-flex>
  78.           <v-flex xs12 sm6 px-3>
  79.          <v-time-picker v-model="time" format="24hr"></v-time-picker>
  80.           </v-flex>
  81.       </v-layout>
  82.                 <v-layout row wrap>
  83.           <v-flex xs12 sm6 offset-sm3 mt-5>
  84.              <v-btn color="success" :disabled="!formIsValid" @click="createMeetup">Create Meetup</v-btn>
  85.           </v-flex>
  86.       </v-layout>
  87.       </v-form>
  88.   </v-container>
  89. </template>
  90. <script>
  91. export default {
  92.     data(){
  93.         return{
  94.             title:'',
  95.             location:'',
  96.             imageUrl:'',
  97.             description:'',
  98.             date:new Date().toISOString().substr(0, 10),
  99.             time:new Date(),
  100.          nameRules: [
  101.         v => !!v || 'Name is required',
  102.         v => (v && v.length <= 10) || 'Name must be less than 10 characters',
  103.       ],
  104.         emailRules: [
  105.         v => !!v || 'E-mail is required',
  106.         v => /^(ftp|http|https):\/\/[^ "]+$/.test(v) || 'E-mail must be valid',
  107.       ],
  108.         }
  109.     },
  110.     computed:{
  111.         formIsValid(){
  112.             return this.title !='' && this.location !='' && this.imageUrl !='' && this.description !=''
  113.         },
  114.         dateAndTime(){
  115.             const date = new Date(this.date)
  116.  
  117.             if(typeof this.time == 'string'){
  118.                 const hours = this.time.match(/^(\d+)/)[1]
  119.                 const minutes = this.time.match(/:(\d+)/)[1]
  120.  
  121.                 date.setHours(hours)
  122.                 date.setMinutes(minutes)
  123.             }
  124.             else{
  125.  
  126.             date.setHours(this.time.getHours());
  127.             date.setMinutes(this.time.getMinutes())
  128.             }
  129.             return date
  130.         }
  131.     },
  132.     methods:{
  133.         createMeetup(){
  134.             const payload = {
  135.                 title:this.title,
  136.                 imageUrl:this.imageUrl,
  137.                 description:this.description,
  138.                 location:this.location,
  139.                 date:this.dateAndTime.toISOString()
  140. }
  141.             this.$store.dispatch("createMeetup",payload)
  142.             this.$router.push('/meetups')
  143.             // this.$refs.form.reset()
  144.  
  145. }
  146.     }
  147. }
  148. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement