Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. <template>
  2. <div class="row">
  3. <div class="col-md-6">
  4. <div class="form-group">
  5. <label for="category_id">
  6. Product Category
  7. </label>
  8.  
  9. <select
  10. name="category_id"
  11. id="category_id"
  12. :class="form.errors.has('category_id') ? 'form-control is-invalid' : 'form-control'"
  13. v-model="form.sharedState.category_id">
  14.  
  15. <option value="" disabled hidden>Select Category</option>
  16. <option
  17. v-for="category in categories"
  18. :key="category.id"
  19. v-text="category.name"
  20. :value="category.id"
  21. @click="$emit('category-selected', category.sub_categories)">
  22. </option>
  23.  
  24. </select>
  25.  
  26. <small
  27. class="form-text text-danger"
  28. v-if="form.errors.has('category_id')"
  29. v-text="form.errors.get('category_id')"></small>
  30.  
  31. </div>
  32. </div>
  33. <div class="col-md-6">
  34. <div
  35. class="form-group"
  36. v-if="revealSubCategory"
  37. @category-selected="show">
  38.  
  39. <label for="category_id">
  40. Sub Category
  41. </label>
  42.  
  43. <select
  44. name="sub_category_id"
  45. id="sub_category_id"
  46. :class="form.errors.has('sub_category_id') ? 'form-control is-invalid' : 'form-control'"
  47. v-model="form.sharedState.sub_category_id">
  48.  
  49. <option value="" disabled hidden>Select Sub Category</option>
  50.  
  51. <option
  52. v-for="subcategory in subcategories"
  53. :key="subcategory.id"
  54. v-text="subcategory.name"
  55. :value="subcategory.id">
  56. </option>
  57.  
  58. </select>
  59.  
  60. <small
  61. class="form-text text-danger"
  62. v-if="form.errors.has('category_id')"
  63. v-text="form.errors.get('category_id')"></small>
  64.  
  65. </div>
  66. </div>
  67. </div>
  68. </template>
  69. <script>
  70. import BaseCard from './BaseCard.vue';
  71.  
  72. export default {
  73. components: {
  74. BaseCard
  75. },
  76. data() {
  77. return {
  78. categories: [],
  79. revealSubCategory: false,
  80. subcategories: [],
  81.  
  82. form: new Form({
  83. sharedState: product.data
  84. })
  85. }
  86. },
  87. mounted() {
  88. this.getCategories();
  89. },
  90. methods: {
  91. getCategories() {
  92. axios.get('categories')
  93. .then(({data}) => this.categories = data);
  94. },
  95. show(subcategories) {
  96. this.revealSubCategory = true;
  97. this.subcategories = subcategories
  98. }
  99. }
  100. }
  101. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement