SchemaFormInputWidget.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. <input
  10. :type="type"
  11. :name="name"
  12. :value="property.default"
  13. :readonly="readonly"
  14. class="form-control"
  15. >
  16. </template>
  17. <script>
  18. export default {
  19. name: 'SchemaFormInputWidget',
  20. props: {
  21. name: {
  22. type: String,
  23. required: true,
  24. },
  25. property: {
  26. type: Object,
  27. required: true,
  28. },
  29. readonly: {
  30. type: Boolean,
  31. default: false,
  32. },
  33. },
  34. computed: {
  35. type() {
  36. let type;
  37. switch (this.property.type) {
  38. case 'number':
  39. case 'integer':
  40. type = 'number';
  41. break;
  42. case 'string':
  43. if (('format' in this.property) && this.property.format.includes('email')) {
  44. type = 'email';
  45. } else {
  46. type = 'text';
  47. }
  48. break;
  49. default:
  50. throw ReferenceError('Unsupported input property, must be type "number", "integer" or "string"');
  51. }
  52. return type;
  53. },
  54. // TODO: Implement step
  55. },
  56. };
  57. </script>