Fix reset workingFromStore, fix star rating required, fix checkboxes

This commit is contained in:
Julien Nahum 2024-01-17 14:52:32 +01:00
parent b4d0008766
commit 1a6b5dd5d7
5 changed files with 19 additions and 21 deletions

View File

@ -69,9 +69,12 @@ class AnswerFormRequest extends FormRequest
if (FormLogicPropertyResolver::isRequired($property, $data)) { if (FormLogicPropertyResolver::isRequired($property, $data)) {
$rules[] = 'required'; $rules[] = 'required';
// Required for checkboxes means true
if ($property['type'] == 'checkbox') { if ($property['type'] == 'checkbox') {
// Required for checkboxes means true
$rules[] = 'accepted'; $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 { } else {
$rules[] = 'nullable'; $rules[] = 'nullable';
@ -148,7 +151,7 @@ class AnswerFormRequest extends FormRequest
return ['string']; return ['string'];
case 'number': case 'number':
if ($property['is_rating'] ?? false) { if ($property['is_rating'] ?? false) {
return ['numeric', 'min:1']; return ['numeric'];
} }
return ['numeric']; return ['numeric'];
case 'select': case 'select':

View File

@ -40,7 +40,9 @@ export default {
}, },
mounted () { mounted () {
this.compVal = !!this.compVal if (!this.compVal) {
this.compVal = false
}
} }
} }
</script> </script>

View File

@ -3,12 +3,11 @@
<input <input
:id="id || name" :id="id || name"
:name="name" :name="name"
:checked="internalValue" v-model="internalValue"
type="checkbox" type="checkbox"
:class="sizeClasses" :class="sizeClasses"
class="rounded border-gray-500 cursor-pointer" class="rounded border-gray-500 cursor-pointer"
:disabled="disabled?true:null" :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}"> <label :for="id || name" class="text-gray-700 dark:text-gray-300 ml-2" :class="{'!cursor-not-allowed':disabled}">
<slot /> <slot />
@ -27,7 +26,6 @@ const props = defineProps({
id: { type: String, default: null }, id: { type: String, default: null },
name: { type: String, default: 'checkbox' }, name: { type: String, default: 'checkbox' },
modelValue: { type: [Boolean, String], default: false }, modelValue: { type: [Boolean, String], default: false },
checked: { type: Boolean, default: false },
disabled: { type: Boolean, default: false }, disabled: { type: Boolean, default: false },
sizeClasses: { type: String, default: 'w-4 h-4' } 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(() => { onMounted(() => {
emit('update:modelValue', internalValue.value) if (internalValue.value === null) {
}) internalValue.value = false
const handleClick = (e) => {
emit('click', e)
if (!e.isPropagationStopped) {
internalValue.value = e.target.checked
emit('update:modelValue', internalValue.value)
} }
} })
</script> </script>

View File

@ -179,7 +179,7 @@ const tabsList = [
] ]
onMounted(() => { onMounted(() => {
workingFormStore.set(null) // Reset old working form workingFormStore.reset()
if (form.value) { if (form.value) {
workingFormStore.set(form.value) workingFormStore.set(form.value)
} else { } else {

View File

@ -45,6 +45,12 @@ export const useWorkingFormStore = defineStore('working_form', {
this.selectedFieldIndex = null this.selectedFieldIndex = null
this.showAddFieldSidebar = false this.showAddFieldSidebar = false
this.showEditFieldSidebar = false this.showEditFieldSidebar = false
},
reset() {
this.content = null
this.selectedFieldIndex = null
this.showEditFieldSidebar = null
this.showAddFieldSidebar = null
} }
} }
}) })