[Bug] Select & boolean fields return null rather than initial value

Hello @formfunfunction

Thanks for reaching out to us.

Did you try to update to the beta: npm install slice-machine-ui@beta

Please find the complete information in this thread.
https://community.prismic.io/t/boolean-default-issue/2652/19

Let me know if it still doesn't solve the issue.

Thanks,
Priyanka

Just wanted to flag that this has been a problem ever since I've been using Prismic, not only with slice machine

Hello @kris

This should be fixed now with the Slice Machine project. Did you try with the Slice Machine?

Thanks,
Priyanka

Hi @Priyanka

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.

Hello @formfunfunction

Sorry for the late response. I was on the vacation. Can you please send me the URL of your repository? You can send me a private message.

Thanks,
Priyanka

Hello @formfunfunction

I have checked with the dedicated developer, and he suggested the following solutions.
Saving boolean fields again should fix it:

  1. Go to your Custom Type
  2. Edit the boolean field and toggle "default to true" and save
  3. Reload the custom type: the default value should still be set to true
  4. Create a new document and save it
  5. Check the value of the field: it should be set to true by default

Please try with this and let me know ow if you still have any issues.

Thanks,
Priyanka

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

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 tested for more context with a fresh custom type.

  1. Create new page
  2. Add slice to that page that has a boolean with default: true
  3. While editing that slice, the boolean is shown in the false state.
  4. After publishing that page, the boolean is shown in the true state.
  5. On rendering my page, the boolean is returned as null.

The only way to resolve this is to edit the page and toggle the boolean field off and on again.

Hello,

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 :slight_smile:

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 also experiencing this problem as many others are.

I'm in a next-js project using slice-machine-ui 1.5.0 in my package-lock.json

Is this issue supposed to be resolved in this version?

Thanks.

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()
1 Like

Same problem, using slice-machine-ui 1.19.1
Please fix this bug.

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?

Hi Thomas,

This is not related to the new editor. We aim to have a resolution on this soon. We'll update this thread once it is done.

Best,
Guy

2 Likes

Any updates ?
This issue is very important. I cannot use the boolean field at the moment.
Thanks

Hi @louisthomas.pro this has been fixed. Let me know if you are still having problems.

Best,
Guy

1 Like