AppInputText.vue 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <script setup>
  2. import { computed } from 'vue'
  3. const props = defineProps({
  4. label: {
  5. type: String,
  6. default: '',
  7. },
  8. disabled: {
  9. type: Boolean,
  10. default: false,
  11. },
  12. placeholder: String,
  13. type: {
  14. type: String,
  15. default: 'text',
  16. },
  17. error: String,
  18. modelValue: [String, Number, Boolean, Array, Object],
  19. })
  20. defineEmits(['update:modelValue'])
  21. const isError = computed(() => (props.error ? true : false))
  22. const forLabel = computed(() => props.label.toLowerCase().replace(/\s+/g, '-'))
  23. const ariaDescribedbyLabel = computed(() => props.label.toLowerCase().replace(/\s+/g, '-') + '-help')
  24. </script>
  25. <template>
  26. <div class="field">
  27. <label :for="forLabel">{{ label }}</label>
  28. <InputText
  29. class="w-full"
  30. :class="{ 'p-invalid': isError }"
  31. :id="forLabel"
  32. :aria-describedby="ariaDescribedbyLabel"
  33. :type="type"
  34. :placeholder="placeholder"
  35. :value="modelValue"
  36. :disabled="disabled"
  37. @input="$emit('update:modelValue', $event.target.value)"
  38. />
  39. <small :id="ariaDescribedbyLabel" :class="{ 'p-error': isError }">
  40. {{ error }}
  41. </small>
  42. </div>
  43. </template>