Skip to content

Beautiful Open-Source Form Builder

Fix reset workingFromStore, fix star rating required, fix checkboxes

Julien Nahum1a6b5dd5d74c
diff --git a/app/Http/Requests/AnswerFormRequest.php b/app/Http/Requests/AnswerFormRequest.php
index 73e6df6e8..9909eae75 100644
--- a/app/Http/Requests/AnswerFormRequest.php
+++ b/app/Http/Requests/AnswerFormRequest.php
@@ -69,9 +69,12 @@ class AnswerFormRequest extends FormRequest
if (FormLogicPropertyResolver::isRequired($property, $data)) {
$rules[] = 'required';
- // Required for checkboxes means true
if ($property['type'] == 'checkbox') {
+ // Required for checkboxes means true
$rules[] = 'accepted';
+ } else if ($property['type'] == 'number' && isset($property['is_rating']) && $property['is_rating']) {
+ // For star rating, needs a minimum of 1 star
+ $rules[] = 'min:1';
}
} else {
$rules[] = 'nullable';
@@ -148,7 +151,7 @@ class AnswerFormRequest extends FormRequest
return ['string'];
case 'number':
if ($property['is_rating'] ?? false) {
- return ['numeric', 'min:1'];
+ return ['numeric'];
}
return ['numeric'];
case 'select':
diff --git a/client/components/forms/CheckboxInput.vue b/client/components/forms/CheckboxInput.vue
index fa37fd415..42f40933f 100644
--- a/client/components/forms/CheckboxInput.vue
+++ b/client/components/forms/CheckboxInput.vue
@@ -40,7 +40,9 @@ export default {
},
mounted () {
- this.compVal = !!this.compVal
+ if (!this.compVal) {
+ this.compVal = false
+ }
}
}
</script>
diff --git a/client/components/forms/components/VCheckbox.vue b/client/components/forms/components/VCheckbox.vue
index 2a140d377..bf8c08ac1 100644
--- a/client/components/forms/components/VCheckbox.vue
+++ b/client/components/forms/components/VCheckbox.vue
@@ -3,12 +3,11 @@
<input
:id="id || name"
:name="name"
- :checked="internalValue"
+ v-model="internalValue"
type="checkbox"
:class="sizeClasses"
class="rounded border-gray-500 cursor-pointer"
:disabled="disabled?true:null"
- @click="handleClick"
>
<label :for="id || name" class="text-gray-700 dark:text-gray-300 ml-2" :class="{'!cursor-not-allowed':disabled}">
<slot />
@@ -27,7 +26,6 @@ const props = defineProps({
id: { type: String, default: null },
name: { type: String, default: 'checkbox' },
modelValue: { type: [Boolean, String], default: false },
- checked: { type: Boolean, default: false },
disabled: { type: Boolean, default: false },
sizeClasses: { type: String, default: 'w-4 h-4' }
})
@@ -53,20 +51,9 @@ watch(() => internalValue.value, (val, oldVal) => {
}
})
-if ('checked' in props) {
- internalValue.value = props.checked
-}
-
onMounted(() => {
- emit('update:modelValue', internalValue.value)
-})
-
-const handleClick = (e) => {
- emit('click', e)
-
- if (!e.isPropagationStopped) {
- internalValue.value = e.target.checked
- emit('update:modelValue', internalValue.value)
+ if (internalValue.value === null) {
+ internalValue.value = false
}
-}
+})
</script>
diff --git a/client/pages/forms/[slug]/show.vue b/client/pages/forms/[slug]/show.vue
index 0686aa089..c8933d84a 100644
--- a/client/pages/forms/[slug]/show.vue
+++ b/client/pages/forms/[slug]/show.vue
@@ -179,7 +179,7 @@ const tabsList = [
]
onMounted(() => {
- workingFormStore.set(null) // Reset old working form
+ workingFormStore.reset()
if (form.value) {
workingFormStore.set(form.value)
} else {
diff --git a/client/stores/working_form.js b/client/stores/working_form.js
index 1b48e835b..2a71eb07b 100644
--- a/client/stores/working_form.js
+++ b/client/stores/working_form.js
@@ -45,6 +45,12 @@ export const useWorkingFormStore = defineStore('working_form', {
this.selectedFieldIndex = null
this.showAddFieldSidebar = false
this.showEditFieldSidebar = false
+ },
+ reset() {
+ this.content = null
+ this.selectedFieldIndex = null
+ this.showEditFieldSidebar = null
+ this.showAddFieldSidebar = null
}
}
})