Iterating Select values in template from other Document (Object + Key)

Is there a way to achieve usage of values in document as dropdown options of Select in a custom template

1 Like

Hey Srini,

At the moment it isn’t possible to define a label and a separate value. The @features-team have an open feature request for this, if/when we ever make a change to this behaviour we’ll update you in this thread.

For now you will need to build the values into your website application. Sorry for the inconvenience.

One solution might be to add values like:
Downtown warehouse [33]

Then in your project use regular expressions to get only numbers inside the brackets:

or js slice to get last 2 digits of the id if it’s always 2 digits"

selectfield.slice(-2);

I know it’s not a great solution but it might help.

Let me know if you have any other questions.

Thanks.

When adding select input to a document type it is only possible to add one string for each option.
This string is then basically both the value and the label for the dropdown that is presented to the user in Prismic.
In html a select input is made up of one or more options each option has a value and a label. Most of the time the label is just a presentation but the value is what matters the most. Sometimes value and label can be the same.

What I suggest is that for a select input in Prismic one should be able to add both value and label.

Prismic api would then deliver back something like:

[field_name] : {value:blue, label: Blue}

ACF for wordpress solves the this problem like this

image

I know I could do this in code by splitting the string by ':', but in my oppinion it would be better that Prismic would handle that.

2 Likes

Hey Kristleifur,

I moved your post here as we're already tracking here as an open feature request. :slight_smile:

Thank you for the detailed explanation and solution as to how this can be achieved.

I offered a solution a solution using regex above, though like your code splitting solution, it requires more work on the developer and custom type creators side. I agree it would cool if we implement this.

If/when there's any update on this I'll let you know here.

This is being tracked as an open feature request.

If you have another use-case for this feature, you can 'Flag' this topic to reopen. Please use the :heart: button to show your support for the feature and check out our Feature Request Guidelines.

Hi,

Is there any update of this feature?
It would be great for a better customer experience using Prismic and also for us to avoid splittings o regex to split label and value. I think this should be a must.

Thank you.

Hi everyone,

Although, for now, a select field with a key and object value is not yet available, once the new builder is fully released, it will give us the flexibility to quickly iterate and add new features based on feedback from users like you.

Our new page builder has been in development for a while now, and we're happy to tell you it's now in Alpha :slight_smile: :tada:

You can read about the page builder in the link below.

BUT PLEASE BE WARNED:
The page builder is still in ALPHA, so there are some features that are not ready (PLEASE CHECK THE LIST).

Join the waitlist to try Prismic's new Page Builder to edit your website.

Thanks :slight_smile:

1 Like

That's great news!
I applied for 2 projects a few weeks ago but I have no access yet, hope I can try it soon. I'm already showing it to future customers and they like it.

I'll send you a pm now and I'll get those repos activated for you.

1 Like