Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

multiple-support #59

Closed
wants to merge 1 commit into from
Closed

multiple-support #59

wants to merge 1 commit into from

Conversation

dominikzogg
Copy link

@dominikzogg dominikzogg commented Aug 18, 2023

For our project we need the possiblity to allow a multiple selection on a select.

demo-ui.png

Can be tested via (same changes, but with commited build)

{
"dependencies": {
    "@payloadcms/plugin-form-builder": "https://github.com/dominikzogg/plugin-form-builder/tarball/multiple-support-build"
  },
}

Frontend example:

Prepare to send:

const dataToSend = Object.entries(data).map(([field, value]) => ({
  field,
  value: Array.isArray(value) ? value.join(', ') : value,
}));

Html:

<select
  id={field.id}
  className="ml-4"
  {...(field.multiple ? { multiple: true } : {})}
  {...register(field.name, { required: field.required })}
>

@dominikzogg
Copy link
Author

@jacobsfletch ping

@dominikzogg
Copy link
Author

dominikzogg commented Oct 11, 2023

It can be done via, instead of my chance, but i believe the PR is still the better solution

formBuilder({
      fields: {
        select: {
          ...fields.select,
          fields: [
            // eslint-disable-next-line @typescript-eslint/ban-ts-comment
            // @ts-ignore
            ...fields.select.fields,
            {
              name: 'multiple',
              label: 'Multiple',
              type: 'checkbox',
            },
          ],
        },
      },
    }),
    ``

@jacobsfletch
Copy link
Member

This plugin is now being maintained in the Packages Directory of the Payload Monorepo. This repo will soon be archived and all open PRs including this one will be closed. Would you be willing to re-open this same PR but within the Payload monorepo? I've included a reference to this PR in this open discussion so that it will not get lost.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants