Skip to content

Commit

Permalink
Handle multi-select input box from package (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
vthwang authored Aug 5, 2023
1 parent 6e15882 commit c056dc6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
24 changes: 5 additions & 19 deletions app/routes/profile-generator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,13 @@ import HandleError from '~/components/HandleError'

export async function action({ request }) {
let formData = await request.formData()
let rawData = {}
let data = {}
for (let key of formData.keys()) {
const values = formData.getAll(key)

// Deal with multiple values submitted as an array
if (key.endsWith('[]')) {
const keyWithoutBrackets = key.slice(0, -2)

if (values.length === 1) {
rawData[keyWithoutBrackets] = []
rawData[keyWithoutBrackets].push(...values)
} else {
rawData[keyWithoutBrackets] = values
}

delete rawData[key]
} else {
rawData[key] = values.length > 1 ? values : values[0]
if (key !== '_action') {
data[key] = formData.getAll(key)
}
}
let { _action, ...data } = rawData
const _action = formData.get('_action')
let schema,
profileId,
profileTitle,
Expand All @@ -61,7 +47,7 @@ export async function action({ request }) {
profileIpfsHash
switch (_action) {
case 'submit':
schema = await parseRef(data.linked_schemas)
schema = await parseRef(data.linked_schemas[0])
profile = await generateInstance(schema, data)
response = await fetchJsonPost(
process.env.PUBLIC_INDEX_URL + '/v2/validate',
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
]
},
"dependencies": {
"@murmurations/jsig": "^1.0.0",
"@murmurations/jsig": "^1.0.1",
"@murmurations/jsrfg": "^1.0.0",
"@remix-run/react": "^1.18.1",
"@vercel/node": "^2.15.3",
Expand Down

1 comment on commit c056dc6

@vercel
Copy link

@vercel vercel bot commented on c056dc6 Aug 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.