keystonejs / keystone-classic

Node.js CMS and web app framework
http://v4.keystonejs.com
MIT License
14.65k stars 2.21k forks source link

Dynamic type select in keystonejs model #4952

Open Rajivkumar1234 opened 4 years ago

Rajivkumar1234 commented 4 years ago

I would like to use a combobox at the adminUI with fields that come from a webservice. I was thinking on get the data with a pre 'find' hook and then override the options atribute at the 'audience' property in the Schema.

Schema

Compliance.add({
  title: { type: Types.Text, required: true, initial: true, index: true }, 
  url: { type: Types.Url, required: true, initial: true },
  position: { type: Types.Number, initial: true },
  audience: { type: Types.Select, options: [], many: true, initial: true},
});

Hook Compliance.schema.pre('find', async function(next) { let audiences = await audienceService.getAudiences(); next(); })

But I didn't find the way to bind the data. Any ideas how this can be done?

Thanks

Rajivkumar1234 commented 4 years ago

@autoboxer Any suggestion to this sir ?

VinayaSathyanarayana commented 4 years ago

Is this going to be available in Keystone-5 @JedWatson

autoboxer commented 4 years ago

@Rajivkumar1234, a Select field is expecting a defined set of options, so as far as I know in Keystone 4 there's no way to dynamically set the values. There may be a way to override the values by accessing and manipulating the field pre-render, but unfortunately I'm not aware of a way to do it.

something like this might be a good place to start: Compliance.fields.audience.__options