1313 color =" primary"
1414 :density =" buttonDensityModel"
1515 :pages =" pages"
16+ :validationSchema =" validationSchema"
1617 :variant =" buttonVariantModel"
1718 @submit =" submitForm"
1819 />
8384 :true-value =" true"
8485 />
8586 </v-col >
86- <v-col
87- class =" py-0"
88- cols =" 12"
89- >
90- <v-checkbox
91- v-model =" multipleModel"
92- v-bind =" optionsSettings"
93- label =" Multiple"
94- :true-value =" true"
95- />
96- </v-col >
9787 <v-col
9888 class =" pb-0"
9989 cols =" 12"
156146</template >
157147
158148<script setup lang="ts">
149+ import {
150+ array as yupArray ,
151+ object as yupObject ,
152+ string as yupString ,
153+ } from ' yup' ;
159154import AnswersDialog from ' ../AnswersDialog.vue' ;
160155
161156
@@ -239,31 +234,37 @@ const buttonDensityOptions = [
239234 value: ' oversized' ,
240235 },
241236];
242- const multipleModel = ref (false );
243237const useIcon = ref (false );
244238
245239
246- const answers = ref <{ iLikeButtons: string | string [] | null | undefined ; }>({
240+ const answers = ref <{
241+ animalsILike: string [] | null | undefined ;
242+ iLikeButtons: string | null | undefined ;
243+ }>({
244+ animalsILike: null ,
247245 iLikeButtons: null ,
248246});
249247
250- watch (() => multipleModel .value , () => {
251- answers .value .iLikeButtons = multipleModel .value ? [] as string [] : null ;
252- });
253-
254248const appendIcon = ref (false );
255249const prependIcon = ref (false );
256250const useColors = ref (false );
257251
258252
253+ watch (() => [useIcon .value , useColors .value , appendIcon .value , prependIcon .value ], () => {
254+ answers .value = {
255+ animalsILike: null ,
256+ iLikeButtons: null ,
257+ };
258+ });
259+
260+
259261const pages = computed (() => [
260262 {
261263 fields: [
262264 {
263265 align: buttonAlignModel ,
264266 block: buttonBlock ,
265267 label: ' I like buttons' ,
266- multiple: multipleModel ,
267268 name: ' iLikeButtons' ,
268269 options: [
269270 {
@@ -290,6 +291,42 @@ const pages = computed(() => [
290291 value: ' maybe' ,
291292 },
292293 ],
294+ required: true ,
295+ type: ' buttons' as const ,
296+ },
297+ {
298+ align: buttonAlignModel ,
299+ block: buttonBlock ,
300+ label: ' I like...' ,
301+ multiple: true ,
302+ name: ' animalsILike' ,
303+ options: [
304+ {
305+ appendIcon: appendIcon .value ? ' mdi:mdi-rabbit' : undefined ,
306+ color: useColors .value ? ' white' : undefined ,
307+ icon: useIcon .value ? ' mdi:mdi-rabbit' : undefined ,
308+ label: ' Bunnies' ,
309+ prependIcon: prependIcon .value ? ' mdi:mdi-rabbit' : undefined ,
310+ value: ' bunnies' ,
311+ },
312+ {
313+ appendIcon: appendIcon .value ? ' mdi:mdi-tortoise' : undefined ,
314+ color: useColors .value ? ' success' : undefined ,
315+ icon: useIcon .value ? ' mdi:mdi-tortoise' : undefined ,
316+ label: ' Turtles' ,
317+ prependIcon: prependIcon .value ? ' mdi:mdi-tortoise' : undefined ,
318+ value: ' turtles' ,
319+ },
320+ {
321+ appendIcon: appendIcon .value ? ' mdi:mdi-duck' : undefined ,
322+ color: useColors .value ? ' yellow' : undefined ,
323+ icon: useIcon .value ? ' mdi:mdi-duck' : undefined ,
324+ label: ' duck' ,
325+ prependIcon: prependIcon .value ? ' mdi:mdi-duck' : undefined ,
326+ value: ' duck' ,
327+ },
328+ ],
329+ required: true ,
293330 type: ' buttons' as const ,
294331 },
295332 ],
@@ -303,6 +340,12 @@ watch(() => pages.value, () => {
303340 exampleKey .value = String (Math .random ());
304341});
305342
343+ const validationSchema = yupObject ({
344+ animalsILike: yupArray ().required (' This field is required.' )
345+ .min (1 , ' Must select at least ${min} option.' ),
346+ iLikeButtons: yupString ().required (' This field is required.' ),
347+ });
348+
306349function submitForm(): void {
307350 dialog .value = true ;
308351}
@@ -373,16 +416,34 @@ const maybeOption = computed(() => buildOption({
373416 value: ' maybe' ,
374417}));
375418
419+ const bunniesOption = computed (() => buildOption ({
420+ color: ' white' ,
421+ icon: ' mdi:mdi-rabbit' ,
422+ label: ' Bunnies' ,
423+ value: ' bunnies' ,
424+ }));
425+
426+ const turtlesOption = computed (() => buildOption ({
427+ color: ' success' ,
428+ icon: ' mdi:mdi-tortoise' ,
429+ label: ' Turtles' ,
430+ value: ' turtles' ,
431+ }));
432+
433+ const duckOption = computed (() => buildOption ({
434+ color: ' yellow' ,
435+ icon: ' mdi:mdi-duck' ,
436+ label: ' duck' ,
437+ value: ' duck' ,
438+ }));
439+
440+
376441const exampleAnswer = computed <string >(() => {
377- if (! answers .value .iLikeButtons || ( answers . value . iLikeButtons as string []). length === 0 ) {
442+ if (! answers .value .iLikeButtons ) {
378443 return ' null' ;
379444 }
380445
381- if (multipleModel .value ) {
382- return ` ${JSON .stringify (answers .value .iLikeButtons )} ` ;
383- }
384-
385- return ` '${answers .value .iLikeButtons as string }' ` ;
446+ return ` '${answers .value .iLikeButtons }' ` ;
386447});
387448
388449const scriptCode = computed (() => (
@@ -398,8 +459,7 @@ const pages = computed(() => [
398459 align: '${buttonAlignModel .value }',
399460 block: ${buttonBlock .value },
400461 label: 'I like buttons',
401- multiple: ${multipleModel .value },
402- name: 'foo',
462+ name: 'iLikeButtons',
403463 options: [
404464 {${yesOption .value }
405465 }
@@ -410,6 +470,22 @@ const pages = computed(() => [
410470 ],
411471 type: 'buttons',
412472 },
473+ {
474+ align: '${buttonAlignModel .value }',
475+ block: ${buttonBlock .value },
476+ label: 'Animals I Like',
477+ multiple: true,
478+ name: 'animalsILike',
479+ options: [
480+ {${bunniesOption .value }
481+ }
482+ {${turtlesOption .value }
483+ },
484+ {${duckOption .value }
485+ }
486+ ],
487+ type: 'buttons',
488+ },
413489 ],
414490 title: 'Page 1',
415491 },
@@ -425,7 +501,7 @@ watch(() => [scriptCode.value, templateCode.value], () => {
425501});
426502
427503const exampleCode = computed (() => ({
428- desc: multipleModel . value ,
504+ desc: ' This example utilizes a custom-built component designed for this form, allowing users to select a value through buttons. ' ,
429505 name: ' Buttons Field' ,
430506 script: scriptCode .value ,
431507 template: templateCode .value ,
0 commit comments