Guest User

Untitled

a guest
Apr 20th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 3.21 KB | None | 0 0
  1. <template>
  2.     <div class="col-md-8">
  3.         <div class="card card-default">
  4.             <div class="card-header">Add Coin</div>
  5.  
  6.             <div class="card-body">
  7.                 <form @submit.prevent="addCoin">
  8.                     <div v-if="errors.length">
  9.                         <b>Please correct the following error(s):</b>
  10.                         <ul>
  11.                             <li v-for="error in errors">{{ error }}</li>
  12.                         </ul>
  13.                     </div>
  14.  
  15.                     <div class="form-group row">
  16.                         <label for="name" class="col-sm-4 col-form-label text-md-right">Name</label>
  17.                         <div class="col-md-6">
  18.                             <input id="email" type="text" class="form-control" v-model="coin.name" autofocus>
  19.                         </div>
  20.                     </div>
  21.  
  22.                     <div class="form-group row">
  23.                         <label for="year" class="col-md-4 col-form-label text-md-right">Year</label>
  24.                         <div class="col-md-6">
  25.                             <input type="text" class="form-control" v-model="coin.year">
  26.                         </div>
  27.                     </div>
  28.  
  29.                     <div class="form-group row">
  30.                         <label for="price" class="col-md-4 col-form-label text-md-right">Price</label>
  31.                         <div class="col-md-6">
  32.                             <input type="text" class="form-control" v-model="coin.price">
  33.                         </div>
  34.                     </div>
  35.  
  36.                     <div class="form-group row mb-0">
  37.                         <div class="col-md-8 offset-md-4">
  38.                             <button @click="validateMe()" :title="title" class="btn btn-primary">
  39.                                 Add
  40.                             </button>
  41.                         </div>
  42.                     </div>
  43.                 </form>
  44.             </div>
  45.         </div>
  46.         <coin-get-component></coin-get-component>
  47.     </div>
  48. </template>
  49.  
  50. <script>
  51.     export default {
  52.         data() {
  53.             return {
  54.                 coin: {},
  55.                 errors: {},
  56.                 title: 'you sure buddy?',
  57.                 isDisabled: true
  58.             }
  59.         },
  60.         methods: {
  61.             addCoin() {
  62.                 // alert('submitted');
  63.                 let uri = 'coins';
  64.                 this.axios.post(uri, this.coin).then((response) => {
  65.                     console.log(response);
  66.                     this.coin.name = '';
  67.                     this.coin.year = '';
  68.                     this.coin.price = '';
  69.                     //window.location.reload();
  70.                 });
  71.                 this.eventBus.$emit('update', data)
  72.  
  73.             },
  74.             validateMe(e) {
  75.                 e.preventDefault();
  76.                 if (this.coin.name && this.coin.year && this.coin.price) return true;
  77.                 this.errors = [];
  78.                 if (!this.coin.name) this.errors.push("Coin Name required.");
  79.                 if (!this.coin.year) this.errors.push("Coin Year required.");
  80.                 if (!this.coin.price) this.errors.push("Coin purchase price required.");
  81.             }
  82.         }
  83.     }
  84. </script>
Add Comment
Please, Sign In to add comment