I have a model below
var User = new keystone.List('User')
User.add({
email: { type: Types.Email, initial: true, required: true, index: true },
country: { type: Types.Select, options: ['usa', 'thailand', 'vietnam'], emptyOption: false},
city: { depends on country field but how to fill here?!!! }
})
I see you supported the dependsOn option in document page
dependsOn Object The field will only be displayed when the paths specified in the object match the current data for the item
But don't see any example for this? Can you help me? Thanks :)
An example:
state: {
type: Types.Select,
options: ['draft', 'published'],
default: 'draft'
},
publishedDate: {
type: Types.Date,
dependsOn: {
state: 'published'
}
}
Thank you @ignlg but that option is not my wanted. Do you know how to create a field that can change (options is enough but type is perfect) when the value of another field is changed as my above example?
It sounds like @superpan3000 wants the list of options available to be dependent on the value of another field. From what I see in the documentation, I don't believe that's something that is supported.
Do we need the ability to call a list method that return any values required by a field? For example:
city: { type: Types.Select, options: getCities }
User.getCities() {
// assume there's a Cities list
var cities = keystone.list('Cities');
cities.model.find( {country: this.country} ).exec(err, items) {
return items || [];
});
}
For #488 dependsOn can also make use of this.
+1 for the ability to pass a function to dependsOn (and maybe other things like options)
In my case, I need to hide a field depending on a fieldvalue of a document that is linked by a relation ...
Yes, what @superpan3000 said.
Did you figure out how to do this?
Moved to keystonejs-site: https://github.com/keystonejs/keystonejs-site/issues/87
Most helpful comment
+1 for the ability to pass a function to dependsOn (and maybe other things like options)
In my case, I need to hide a field depending on a fieldvalue of a document that is linked by a relation ...