Skip to content

Commit

Permalink
fix(state): Missing input disabled state, while submitting a form via…
Browse files Browse the repository at this point in the history
… XHR/Fetch request. #35
  • Loading branch information
sfxcode committed Feb 24, 2024
1 parent cde58f2 commit 7cb09aa
Show file tree
Hide file tree
Showing 26 changed files with 42 additions and 28 deletions.
15 changes: 15 additions & 0 deletions src/components/demo/PrimeInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { FormKitSchema } from '@formkit/vue'
import { ref } from 'vue'
import JsonEditorVue from 'json-editor-vue'
import { useToast } from 'primevue/usetoast'
import type { ToastMessageOptions } from 'primevue/toast'
const props = defineProps<{
header: string
Expand All @@ -11,14 +13,26 @@ const props = defineProps<{
customAttributes?: string
}>()
const toast = useToast()
function showMessage(severity: ToastMessageOptions['severity'], summary: string, detail: string) {
toast.add({ severity, summary, detail, life: 1000 })
}
const formSchema = ref(props.schema)
const formData = ref(props.data)
const documentationLink = `https://primevue.org/${props.header.replace('Prime', '').toLowerCase()}`
async function submitHandler() {
showMessage('success', 'Form Submitted ...', 'Form submitted successfully')
await new Promise(resolve => setTimeout(resolve, 2000))
}
</script>

<template>
<div>
<Toast position="bottom-right" />
<h2 class="text-color-[var(--primary-color)] pb-2">
{{ header }}
</h2>
Expand All @@ -32,6 +46,7 @@ const documentationLink = `https://primevue.org/${props.header.replace('Prime',
:submit-attrs="{
inputClass: 'p-button p-component',
}"
@submit="submitHandler"
>
<FormKitSchema :schema="formSchema" :data="formData" />
</FormKit>
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeAutoComplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<AutoComplete
:id="context.id"
v-model="context._value"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:tabindex="attrs.tabindex"
:aria-label="attrs.ariaLabel"
:aria-labelledby="attrs.ariaLabelledby"
Expand Down
4 changes: 2 additions & 2 deletions src/formkit/PrimeCalendar.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang='ts'>
import {CalendarBlurEvent} from "primevue/calendar";
import type { CalendarBlurEvent } from 'primevue/calendar'
const props = defineProps({
context: Object,
Expand Down Expand Up @@ -32,7 +32,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<Calendar
v-model="context._value"
:input-id="props.context.id"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:input-style="attrs.style"
:input-class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeCascadeSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<CascadeSelect
:id="context.id"
v-model="context._value"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:list-style="attrs.style"
:class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeCheckbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<Checkbox
v-model="context._value"
:input-id="context.id"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:input-style="attrs.style"
:input-class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeChips.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<Chips
v-model="context._value"
:input-id="context.id"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:input-style="attrs.style"
:input-class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeColorPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function handleChange(e: any) {
<div class="p-formkit">
<ColorPicker
v-model="context._value"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:style="attrs.style"
:panel-class="attrs.class"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<Dropdown
v-model="context._value"
:input-id="context.id"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:style="attrs.style"
:class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<Editor
:id="context.id"
v-model="context._value"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:editor-style="attrs.style"
:class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeInputMask.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<InputMask
:id="context.id"
v-model="context._value"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:editor-style="attrs.style"
:class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeInputNumber.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<InputNumber
v-model="context._value"
:input-id="context.id"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:input-style="attrs.style"
:input-class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeInputSwitch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<InputSwitch
v-model="context._value"
:input-id="context.id"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:input-style="attrs.style"
:input-class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeInputText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<InputText
:id="context.id"
v-model="context._value"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:style="attrs.style"
:class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeKnob.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<Knob
:id="context.id"
v-model="context._value"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:style="attrs.style"
:class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeListbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<Listbox
:id="context.id"
v-model="context._value"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:list-style="attrs.style"
:class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeMultiSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<MultiSelect
v-model="context._value"
:input-id="context.id"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:list-style="attrs.style"
:class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimePassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<Password
v-model="context._value"
:input-id="context.id"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:input-style="attrs.style"
:input-class="styleClass"
Expand Down
3 changes: 3 additions & 0 deletions src/formkit/PrimeRadioButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<div :class="attrs.options_class" class="p-formkit">
<div v-for="option in attrs.options" :key="option.value" :class="attrs.option_class">
<RadioButton
:id="context.id"
v-model="context._value"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:name="attrs.name"
:value="option.value"
:input-style="attrs.style"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeRating.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<Rating
:id="context.id"
v-model="context._value"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:style="attrs.style"
:class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeSelectButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<SelectButton
:id="context.id"
v-model="context._value"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:style="attrs.style"
:class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeSlider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<Slider
:id="context.id"
v-model="context._value"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:style="attrs.style"
:class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeTextarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<Textarea
:id="context.id"
v-model="context._value"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:style="attrs.style"
:class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeToggleButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<ToggleButton
v-model="context._value"
:input-id="context.id"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:input-style="attrs.style"
:input-class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeTreeSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<TreeSelect
v-model="context._value"
:input-id="context.id"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:input-style="attrs.style"
:input-class="styleClass"
Expand Down
2 changes: 1 addition & 1 deletion src/formkit/PrimeTriStateCheckbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const styleClass = computed(() => (context?.state.validationVisible && !context?
<TriStateCheckbox
v-model="context._value"
:input-id="context.id"
:disabled="attrs._disabled ?? false"
:disabled="attrs._disabled ?? !!context?.disabled"
:readonly="attrs._readonly ?? false"
:input-style="attrs.style"
:input-class="styleClass"
Expand Down
4 changes: 0 additions & 4 deletions src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ const schema = reactive(
)
const data = ref({ email: 'tom@sfxcode.com' })
async function submitHandler() {
await new Promise(resolve => setTimeout(resolve, 1000))
}
</script>

<template>
Expand Down

0 comments on commit 7cb09aa

Please sign in to comment.