keystone-classic icon indicating copy to clipboard operation
keystone-classic copied to clipboard

Muti select on Types.select

Open Rajivkumar1234 opened this issue 4 years ago • 5 comments

Is this feature has been added to keystone js ?

Rajivkumar1234 avatar Aug 02 '19 07:08 Rajivkumar1234

It does not provide multi select for field type Select. but you can create another List which contains all the values you want to use as select, then use this as Relationship field with many: true in option. see https://keystonejs.netlify.com/api/field/relationship

if you want to have fixed number of items like select, use list option like this and use application update feature which will create the initial items for you, (list options are skipped at this time)

 {
  noedit: false,
  nocreate: false,
  nodelete: false,
}

see - https://keystonejs.netlify.com/api/list for more list options.

gautamsi avatar Aug 02 '19 07:08 gautamsi

My Problem Is this , I hope someone from the community can address or answer this one.

  • I would like to use a combobox at the adminUI with fields that come from a server or a query from a seperate model. I was thinking on get the data with a pre 'find' hook and then override the options atribute at the 'audiences' property in the Schema.

  • This is the solution I am trying to address and made possible

    • I did try to push values from the pre find hook to audiences and then
    • overide the options value but But I didn't find the way to bind the data. Any ideas how this can be done?

var audiences = []

#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: audiences , many: true, initial: true },
});```

#Hook

Compliance.schema.pre('save', function (next) {
    keystone.list('AnotherModel').model.find()
        .exec(function (err, results) {
            var modelresults = results
            for (i = 0; i < modelresults i++) {
                audiences .push(modelresults s[i].name)
   
            }

        });

});

  • Now here comes the second problem the Multi select on types.select

    • Let as say we solve the problem above and was able to overide data to options
    • It should be able to multi select from the values of options but keystone does not support that.
    • I doubt there will be a solution to this . Is there ?
  • Now they say that Relationship could be able to solve this issue , But

But what if all the data that I wanted to get comes from a single model ?


TestModel.add({
    name: { type: String, required: true },
    year: { type: String, required: true },
    model: { type: String, required: true },
}); 


#And on my TestModel2


var listdata = ["1999", "2020"]
var listdata1 = ["model1", "model2"]
var listdata2 = ["Name 1", "Name"]

  TestModel2.add({
    name: { type: String, required: true },
    value: { type: String },
    name: { type: Types.Select, options: listdata2},
    year: { type: Types.Select, options: listdata1},
    model: { type: Types.Select, options: listdata},
}); 


How does relationship be able to solve this problem , kindly see screenshot. I just did use arrays on the example above , data should supposed to be from TestModel , I wanted to get all the data from TestModel to TestModel2 which would be 1 select menu for name , year and model and must be able to select multiple data each select menu. How can a Relationship be able to address that ?

Screenshot https://imgur.com/a/mp6KXEp

Rajivkumar1234 avatar Aug 02 '19 09:08 Rajivkumar1234

@gautamsi , @autoboxer . Any Idea that could help ? Thank you. @JedWatson .Thank you.

Rajivkumar1234 avatar Aug 02 '19 09:08 Rajivkumar1234

Are you sure you aren't looking for https://keystonejs.netlify.com/api/field/relationship/ ? It will create a select with all the values of that other model. Setting it to many: true will make it a multiselect.

laurenskling avatar Aug 28 '19 06:08 laurenskling

it will not do multiselect

ibrahimjamil avatar Nov 22 '21 20:11 ibrahimjamil