keystonejs / keystone-classic

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

Muti select on Types.select #4953

Open Rajivkumar1234 opened 5 years ago

Rajivkumar1234 commented 5 years ago

Is this feature has been added to keystone js ?

gautamsi commented 5 years ago

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.

Rajivkumar1234 commented 5 years ago

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

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)

            }

        });

});

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 commented 5 years ago

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

laurenskling commented 5 years ago

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.

ibrahimjamil commented 3 years ago

it will not do multiselect