I need to fetch a document and get all the fields values as well as their type (i.e keytext, image, slice, etc) from prismic. Do you know any way to do that? Right now it's up to me to parse the data and figure out the type of each field in the front end which is complicated.
Thanks,
Lindsay
Welcome to the Prismic Forum and thanks for reaching out to us.
It's not possible to fetch the type of Prismic component with API V2. As you said, you need to do it on the front end. I am curious to know why do you want to check the type of each field on the front end?
Thanks,
Priyanka
system
(system)
closed as resolved, flag & select 'Something Else' to reopen.
4
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
Is there any update on this topic? It would be quite useful to know the field type when working with prismic. I am quite surprised that the field type is not included with the payload. There is a helper function isFilled that somewhat works for determining the field type but it is fundamentally flawed. It will return return true for incorrect field content.
prismicH.isFilled is an object containing small functions that determine if a field has a value. It will be useful to display fallback content. It doesn't determine the field type.
The isFilled helper functions are not very helpful as they require you to know the field type and there is no mechanism for determining the field type.
For example field content that is rich text may be considered a filled number field or a filled integration field.
const value = [{
"type": "paragraph",
"text": "A sleeping orange cat being held in an arm.",
"spans": []
}]
isFilled.integrationFields(value) // returns true
isFilled.number(value) // returns true
We are missing basic functionality to determine the field type.