Skip to content
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

Bugfix/invalid field format #661

Merged
merged 2 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Drag & drop file upload #653
- Disallow use of "any" type #624
- Date picker #559
- New login page #573
- Autocomplete name field in DOI form #529
Expand Down Expand Up @@ -67,6 +68,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Cast integer fields as numbers #661
- Disallow object update with invalid form #656
- Handle required form array fields #484
- Prevent user deleting object in published folder #486
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ const cleanUpFormValues = (data: unknown) => {
return traverseFormValuesForCleanUp(cleanedData)
}

// Array is populated in traverseFields method.
const integerFields: Array<string> = []

const traverseFormValuesForCleanUp = (data: Record<string, unknown>) => {
Object.keys(data).forEach(key => {
const property = data[key] as Record<string, unknown> | string | null
Expand All @@ -143,7 +146,11 @@ const traverseFormValuesForCleanUp = (data: Record<string, unknown>) => {
}
if (property === "") {
delete data[key]
} else if (typeof property === "string" && !isNaN(Number(data[key])) && key !== "telephoneNumber") {
}
// Integer typed fields are considered as string like ID's which are numbers.
// Therefore these fields need to be handled as string in the form and cast as number
// for backend operations. Eg. "1234" is converted to 1234 so it passes backend validation
else if (integerFields.indexOf(key) > -1) {
data[key] = Number(data[key])
}
})
Expand Down Expand Up @@ -275,6 +282,10 @@ const traverseFields = (
)
}
case "integer": {
// List fields with integer type in schema. List is used as helper when cleaning up fields for backend.
const fieldName = name.split(".").pop()
if (fieldName && integerFields.indexOf(fieldName) < 0) integerFields.push(fieldName)

return <FormTextField key={name} name={name} label={label} required={required} description={description} />
}
case "number": {
Expand Down