Skip to content

Commit ca4a56c

Browse files
committed
feat: enhance repeater component with new input handling and improved list structure
1 parent e5f41ca commit ca4a56c

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

playground/formkit.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const config: DefaultConfigOptions = {
2727
// default:
2828
global: ['outer', 'inner'],
2929
form: ['form'],
30+
nuxtUIRepeater: ['input'],
3031
},
3132
),
3233
addNuxtAsteriskPlugin,

src/runtime/formkit/definitions/repeater.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ export const nuxtUIRepeaterDefinition: FormKitTypeDefinition = createInput(
2929
addList('$listName', [
3030
addInsertButton('$insertButtonLabel', 'i-lucide-plus', '$insertButtonClass', '$insertButtonSize', '$node.children.length == 0 || $alwaysDisplayInsertButton'),
3131
addListGroup([
32-
addElement('li', [{ children: '$slots.default' }, addButtonGroup('$buttonGroupClass', '$buttonGroupItemClass', '$buttonSize', '$renderButtons')], { class: '$internalListItemClass' })], true, {}),
32+
addElement('li', [{ children: '$slots.default' }, addButtonGroup('$buttonGroupClass', '$buttonGroupItemClass', '$buttonSize', '$renderButtons')],
33+
{ class: '$internalListItemClass' })], true, {}),
3334
], true, 'true'),
34-
], { class: '$internalListClass' }),
35+
], { class: '$internalListClass' }, true),
3536
{
3637
props: ['insertButtonLabel', 'insertButtonClass', 'insertButtonSize', 'alwaysDisplayInsertButton', 'newItem', 'listClass', 'listItemClass',
3738
'hideButtonGroup', 'hideMoveButtons', 'buttonGroupClass', 'buttonGroupItemClass', 'buttonSize', 'displayCloneButton', 'displayAddButton', 'displayDeleteButton'],
@@ -53,13 +54,13 @@ function addRepeaterHandler(node: FormKitNode): void {
5354
node.context.insertButtonSize = node.context.insertButtonSize ? node.context.insertButtonSize : 'md'
5455
node.context.buttonSize = node.context.buttonSize ? node.context.buttonSize : 'md'
5556
node.context.renderMoveButtons = !node.context.hideMoveButtons
57+
node.context.internalListClass = node.context.listClass ? `formkit-items ${node.context.listClass}` : 'formkit-items'
5658
node.context.internalListItemClass = node.context.listItemClass ? `formkit-item ${node.context.listItemClass}` : 'formkit-item'
5759

5860
node.context.insertNode = (parentNode: FormKitNode) => (): void => {
5961
if (parentNode && parentNode._value instanceof Array) {
6062
const item: object = node.context.newItem ? { ...node.context.newItem } : {}
6163
const newArray: object[] = [item, ...parentNode._value]
62-
parentNode.input([], false)
6364
parentNode.input(newArray, false)
6465
}
6566
}

0 commit comments

Comments
 (0)