3

I used Select field but creating with manual select option.I have categories list and I want to create another list which includes category field.I would like to do it with fetching all categories into my Select field to choose which category I want.How can i do this dynamical ? Thanks in advance!

const { Text, Select } = require('@keystonejs/fields');
const {Keystone} = require('@keystonejs/keystone');
const options = [
    { value: 'YES', label: "Yes, I'll be there!" },
    { value: 'NO', label: "Sorry, I can't make it :(" },
    { value: 'MAYBE', label: 'Not sure yet' },
];




module.exports={
    fields:{
        levels:{
            type:Select,
            options,
            isRequired:true

        },
        tm: {
            type: Text,
            isRequired:true,
            isUnique:true,


        },
        ru: {
            type: Text,
            isRequired:true,
            isUnique:true,

        },
        en: {
            type: Text,
            isRequired:true,
            isUnique:true,

        },

    },


}
Roa
  • 437
  • 4
  • 14

1 Answers1

0

I believe this question (and answer) might be useful to you: Dynamic type select in keystonejs model. It was to me.

In short, you can use a function in stead of an array for options. With the function returning an array for the options.

etf213
  • 86
  • 5