Iterating Select values in template from other Document

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.

1 Like

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.