-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ListboxInput component for selecting multiple options and use it for barbuddies #562
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,8 +1,8 @@ | ||||||||||
<i18n lang="yaml"> | ||||||||||
en: | ||||||||||
success: The bar buddy you selected will contact you as soon as possible. | ||||||||||
success: A bar buddy you selected will contact you as soon as possible. | ||||||||||
nl: | ||||||||||
success: Je barbuddy neemt zo snel mogelijk contact met je op. | ||||||||||
success: Een barbuddy neemt zo snel mogelijk contact met je op. | ||||||||||
</i18n> | ||||||||||
|
||||||||||
<script setup> | ||||||||||
|
@@ -12,19 +12,23 @@ const props = defineProps({ | |||||||||
barBuddies: { type: Array, required: true }, | ||||||||||
}) | ||||||||||
|
||||||||||
const form = useReMemberForm('barbuddy', { | ||||||||||
const form = useReMemberForm('barbuddy2', { | ||||||||||
name: '', | ||||||||||
age: '', | ||||||||||
language: locale.value === 'nl' ? 'dutch' : 'english', | ||||||||||
email: '', | ||||||||||
phone_number: '', | ||||||||||
pronouns: '', | ||||||||||
barbuddy: 'no_preference', | ||||||||||
buddy_preferences: 'no_preference', | ||||||||||
buddies: [], | ||||||||||
remarks: '', | ||||||||||
}) | ||||||||||
|
||||||||||
const formElement = ref(null) | ||||||||||
const submit = async () => { | ||||||||||
if (form.fields.buddies.length > 0) { | ||||||||||
form.fields.buddy_preferences = form.fields.buddies.join(', ') | ||||||||||
} | ||||||||||
await form.submit() | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I'd do something like this and remove the previous 3 lines + the property on line 22 |
||||||||||
window.scrollTo({ top: formElement.value.offsetTop, behavior: 'smooth' }) | ||||||||||
} | ||||||||||
|
@@ -61,7 +65,7 @@ const barBuddyOptions = Object.fromEntries(props.barBuddies.map((buddy) => [budd | |||||||||
dutch: $t('forms.label.languages.dutch'), | ||||||||||
english: $t('forms.label.languages.english'), | ||||||||||
no_preference: $t('forms.label.languages.no_preference'), | ||||||||||
}" | ||||||||||
}" | ||||||||||
/> | ||||||||||
</ElementsFormElement> | ||||||||||
|
||||||||||
|
@@ -70,13 +74,7 @@ const barBuddyOptions = Object.fromEntries(props.barBuddies.map((buddy) => [budd | |||||||||
</ElementsFormElement> | ||||||||||
|
||||||||||
<ElementsFormElement name="barbuddy" :errors="form.validationErrors"> | ||||||||||
<ElementsFormRadioInput | ||||||||||
v-model="form.fields.barbuddy" | ||||||||||
:options="{ | ||||||||||
no_preference: $t('forms.label.languages.no_preference'), | ||||||||||
...barBuddyOptions, | ||||||||||
}" | ||||||||||
/> | ||||||||||
<ElementsFormListboxInput v-model="form.fields.buddies" :options="barBuddyOptions" /> | ||||||||||
</ElementsFormElement> | ||||||||||
|
||||||||||
<ElementsFormElement name="remarks" :errors="form.validationErrors"> | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice, still surprised this works, awesome |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script setup> | ||
import { ref } from 'vue' | ||
import { | ||
Listbox, | ||
ListboxLabel, | ||
ListboxButton, | ||
ListboxOptions, | ||
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these are unused There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (and the ref import as well) |
||
ListboxOption, | ||
} from '@headlessui/vue' | ||
import { IconCheckmark } from '@iconify-prerendered/vue-zondicons' | ||
|
||
|
||
defineProps({ | ||
options: { type: Object, required: false }, | ||
}) | ||
const model = defineModel() | ||
</script> | ||
|
||
<template> | ||
<Listbox v-model="model" multiple> | ||
<div class="flex flex-wrap space-x-2"> | ||
<ListboxOption v-slot="{ selected }" v-for="[value, description] in Object.entries(options)" :key="value" | ||
:value="value" as="template"> | ||
<button type="button" class="rounded-lg px-4 py-3 flex items-center transition-colors my-1" | ||
:class="selected ? 'bg-gray-800 text-white' : 'bg-white text-gray-800 hover:bg-gray-300'"> | ||
{{ description }} | ||
<div v-if="selected" | ||
class="ml-2 w-5 h-5 rounded-full bg-white text-gray-800 flex items-center justify-center"> | ||
<IconCheckmark class="w-2 h-2" /> | ||
</div> | ||
</button> | ||
</ListboxOption> | ||
</div> | ||
</Listbox> | ||
</template> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, I forgot, why can't we use the old form still?
Since we're just comma seperating the bar buddies I think we could just as well stick them into the original
barbuddy
property