Comments (1)
I made an attempt on this, but we have complex interactions in our Forms and I couldn't wrangle this one in the time I had yesterday. I'm posting my findings as a starting point for the next attempt to fix this. I would put this effort into v3 currently the alpha branch at this point.
The function for reducing Fields to values that get sent to the server is here: packages/payload/src/admin/components/forms/Form/reduceFieldsToValues.ts
It calls a utility function called unflatten that we've imported from the flatley
package. It is murdering your dot notation by making nested objects. I attempted to fix this by bypassing the unflatten conditionally depending on the field type. This doesn't work because for some reason the fields
type has a conditional fieldSchema?: Field
property. I don't know why fieldSchema isn't always available, but this function is called from a great many places and at this point I'm not sure if this is the best fix. It might be better to use the form overrides, but I'm not familiar enough with that to take this further.
Here is my logic that doesn't work without fieldSchema sadly:
import { unflatten as flatleyUnflatten } from 'flatley'
import type { Data, Fields } from './types'
/**
* Reduce flattened form fields (Fields) to just map to the respective values instead of the full FormField object
*
* @param unflatten This also unflattens the data if `unflatten` is true. The unflattened data should match the original data structure
* @param ignoreDisableFormData - if true, will include fields that have `disableFormData` set to true, for example, blocks or arrays fields.
*
*/
const reduceFieldsToValues = (
fields: Fields,
unflatten?: boolean,
ignoreDisableFormData?: boolean,
): Data => {
const data = {}
const unflattenedData = {}
Object.keys(fields).forEach((key) => {
if (ignoreDisableFormData === true || !fields[key].disableFormData) {
if (unflatten && fields[key].fieldSchema?.type === 'json') {
unflattenedData[key] = fields[key].value
} else {
data[key] = fields[key].value
}
}
})
if (unflatten) {
return {...flatleyUnflatten(data, { safe: true }), ...unflattenedData}
}
return data
}
from payload.
Related Issues (20)
- [3.0 Beta] Having a `data` folder in root breaks build HOT 7
- [3.0] SyntaxError when generating types HOT 4
- Nested Docs URL conflicts when using same slug with different parents HOT 4
- [BUG] Nested groups in nested blocks
- afterChange hook runs before data is persisted to the database ? HOT 4
- Race condition causing documents to disappear from CMS
- Payload-Lexical: link tooltip pops up on selecting a decorator node HOT 2
- Payload-Lexical: link tooltip pops up on selecting a decorator node HOT 1
- [3.0] JSON Field crashes if no default value provided HOT 2
- [3.0 CLI] Mongodb used when Postgres is selected HOT 4
- HTTP POST request to /api throw "Error: Unexpected end of form" at Multipart._final HOT 2
- Relationship filter not adding items to dropdown after making request for next page
- Incorrectly typed/exported CellComponentProps?
- Postgres Adapter: there is no parameter $1 HOT 5
- table names changed updating from 2.11.2 to 2.13.0 HOT 2
- Field is still saved even though it is set to read-only HOT 1
- plugin-cloud-storage: saving an existing upload gives FileUploadError HOT 1
- plugin-cloud-storage: S3 upload error HOT 3
- Incorrect collection displayed in list deletion toast HOT 2
- Cannot use Slate editor, webpack complains about missing exports that are clearly there HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from payload.