Advertisement
Guest User

Untitled

a guest
Aug 9th, 2020
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. <template>
  2. <b-col md="4" class="m-3">
  3. <b-card header="Add Product">
  4. <b-card-body>
  5. <b-form onautocomplete="off">
  6. <b-form-group
  7. label="Name">
  8.  
  9. <b-form-input v-validate="{required: true, min: 3}" v-model="form.name" id="name" name="name" trim></b-form-input>
  10. <div v-if="submitted" class="error-message ">
  11. {{errors.first('name')}}
  12. </div>
  13.  
  14. </b-form-group>
  15. <b-form-group
  16. label="Price ($)">
  17.  
  18. <b-form-input v-validate="{required: true, numeric: true}" v-model="form.price" id="price" name="price" trim></b-form-input>
  19. <div v-if="submitted" class="error-message ">
  20. {{errors.first('price')}}
  21. </div>
  22. </b-form-group>
  23. <b-form-group
  24. label="Brand">
  25.  
  26. <b-form-input v-validate="{required: true}" v-model="form.brand" id="brand" name="brand" trim></b-form-input>
  27. <div v-if="submitted" class="error-message ">
  28. {{errors.first('brand')}}
  29. </div>
  30. </b-form-group>
  31.  
  32. <div>
  33. <b-form-group label="Inventory ?">
  34. <div v-if="submitted" class="error-message ">
  35. {{errors.first('inventorystatus')}}
  36. </div>
  37. <b-form-radio v-validate="{required: true}" v-model="form.inventoryStatus" name="inventorystatus" value="true">In stock</b-form-radio>
  38. <b-form-radio v-model="form.inventoryStatus" name="inventorystatus" value="false">Out of stock</b-form-radio>
  39. </b-form-group>
  40.  
  41. </div>
  42.  
  43. </b-form>
  44. </b-card-body>
  45.  
  46. <b-button block variant="primary" @click="addProduct">Add Product</b-button>
  47. </b-card>
  48. </b-col>
  49. </template>
  50.  
  51. <script>
  52. export default {
  53. name: "AddProduct",
  54. data() {
  55. return {
  56. form : {
  57. name: '',
  58. price: '',
  59. brand: '',
  60. inventoryStatus: ''
  61. },
  62. submitted: false
  63. }
  64.  
  65. },
  66. methods: {
  67. async addProduct() {
  68. this.submitted = true
  69. let result = await this.validator.validate()
  70. if (result) {
  71. this.$emit('addProduct', {
  72. name: this.from.name,
  73. price: '$' + this.from.price,
  74. brand: this.from.brand,
  75. inventoryStatus: this.from.inventorystatus === 'true'
  76. })
  77.  
  78. }
  79. console.log(result)
  80. console.log(this.form)
  81. }
  82. }
  83.  
  84. }
  85. </script>
  86.  
  87. <style scoped>
  88.  
  89. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement