SchemaForm.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <!--
  2. Copyright 2019 Hackware SpA <human@hackware.cl>
  3. This file is part of "Hackware Userland" and licensed under the terms
  4. of the GNU Affero General Public License version 3, or (at your option)
  5. a later version. You should have received a copy of this license along
  6. with the software. If not, see <https://www.gnu.org/licenses/>.
  7. -->
  8. <template>
  9. <div class="schema-form">
  10. <div
  11. v-for="(propertyObject, propertyName) in jsonSchema.properties"
  12. :key="propertyName"
  13. class="form-group"
  14. >
  15. <label :for="propertyName">
  16. {{ propertyObject.title }}
  17. {{ isRequired(propertyName) ? '*' : '' }}
  18. </label>
  19. <SchemaFormWidget
  20. :id="propertyName"
  21. :name="propertyName"
  22. :property="propertyObject"
  23. :required="isRequired"
  24. />
  25. </div>
  26. </div>
  27. </template>
  28. <script>
  29. import SchemaFormWidget from './SchemaFormWidget.vue';
  30. export default {
  31. name: 'SchemaForm',
  32. components: {
  33. SchemaFormWidget,
  34. },
  35. props: {
  36. jsonSchema: {
  37. type: Object,
  38. required: true,
  39. },
  40. },
  41. methods: {
  42. isRequired(propertyName) {
  43. return ('required' in this.jsonSchema) && this.jsonSchema.required.includes(propertyName);
  44. },
  45. },
  46. };
  47. </script>