Hello, we're having an issue with some fields in slices created using Slice Machine.
When we add a slice using the visual editor, many select and boolean fields have a default value, however when the new document is saved (leaving these default values selected and unchanged), the response from the Prismic API for these fields is null, rather than the default value (true/false, or the value in the select field).
The only way to fix it is to select a different value, save the document, change it back to the first value and save the document again.
We can work around the issue by treating a null response as if it's the default value, but it would be great if the API matched what's selected in the visual editor. Is there anything we could be doing wrong that's causing this?
Thanks for the reply! My project has always been using the beta version of slice-machine-ui. My yarn.lock file references 0.1.0-beta.2.
I just double-checked I was on the latest version anyway, made sure the defaults were all set correctly on my slice, re-saved and pushed the slice, but when I create a new document all the select and boolean fields are still null.
This issue still occurs. When my slices are added to a page, a boolean is still being shown as false by default, and is returning null in the application, despite the config having "default_value": true (set via slice machine).
I just wanted to bring to your attention that we are still experiencing the issue. At the moment, we are in the process of migrating content from our existing Prismic repository, which uses legacy Slices, to a new repository using newly built Slice Machine Slices. The migration process involves more than 1,000 documents, so it would be impractical to perform the workaround manually for all of them. While we could treat a null response as if it were the default value to work around the issue, this approach is not sustainable. Future Slice developers on our repository may not be aware of this issue or may forget, leading to confusion and wasted time when they inevitably encounter the same problem.
I was wondering if the Prismic engineering team is planning to address this bug. Do you have any information on a timeline for a fix? Thank you in advance for your assistance
Yes I have also noticed this... My boolean and select fields have defaults set, but unless I interact with the setting by turning it on / off / on, etc it returns null instead of the default.
I can check which version of slice machine etc im using but its all fairly recent since I only started building around 6 weeks ago.
I'm experiencing the same problem in a new project, running slice-machine-ui 1.8.0 (select and boolean fields returning null despite having set defaults).
I've had this same problem since the very beginning. To get around it, I always end up creating a few global helper functions with notes. Not pretty, but if they do fix it, you don't need to update anything and it will still work.
global helpers file
export function getSliceBoolean(value){
//if prismic defaulting fails set to TRUE
return value == null ? true : value
}
export function getSliceSelect(selects,value){
// if prismic defaulting fails return FIRST item
if(!value) return selects[0]
return selects.find(o => o == value)
}
slice file with boolean
import {getSliceBoolean} from '@/helpers'
const foo = getSliceBoolean(slice.primary.bar)
slice file with select
import {getSliceSelect} from '@/helpers'
// copy in selects from './model.json'
const selects = ["Large", "Medium", "Small"]
const value = getSliceSelect(selects, slice.primary.foo).toUpperCase()
We're also facing the same issue when using the api directly. If the default value hasn't been changed the api will just return null instead of the default value.
Not sure if this has to do with the new editor?