Reputation: 675
I've created such a model:
var keystone = require('keystone'),
Types = keystone.Field.Types;
var Page = new keystone.List('Page', {
autokey: { path: 'slug', from: 'menuTitle', unique: true },
map: { name: 'menuTitle' },
});
Page.add({
keyword: { type: Types.Key, required: true, initial: false },
slug: { type: Types.Key, required: true, initial: false },
type: { type: Types.Select, options: 'textpage, projects, services, contacts, homepage', default: 'textpage' },
menuTitle: { type: String, required: true, initial: false },
pageTitle: { type: String },
pageContent: { type: Types.Html, wysiwyg: true, height: 400 },
seoTitle: { type: String },
seoKeywords: { type: String },
seoDescription: { type: String },
isActive: { type: Types.Boolean }
});
Page.defaultColumns = 'keyword, slug, menuTitle, isActive';
Page.register();
I expected it will generate a list of objects and a form to create these objects.
But the form has no fields.
What am I doing wrong? Or what else should I do to get a form with all my fields?
Upvotes: 3
Views: 1686
Reputation: 20378
Basically, you're not seeing any fields because you have the initial
option set to false
on them all.
initial
defaults to false
, except for the "name" field - i.e. by default a field with the path name
or a path that matches the mapping you've given Keystone for name
, in your case menuTitle
.
So normally your menuTitle
field would show up, expect you're explicitly telling it not to with the initial: false
setting.
To get fields to show up, simply set the ones you want to initial: true
, like this:
var keystone = require('keystone'),
Types = keystone.Field.Types;
var Page = new keystone.List('Page', {
autokey: { path: 'slug', from: 'menuTitle', unique: true },
map: { name: 'menuTitle' },
});
Page.add({
keyword: { type: Types.Key, required: true, initial: true },
type: { type: Types.Select, options: 'textpage, projects, services, contacts, homepage', default: 'textpage' },
menuTtle: { type: String, required: true, initial: true },
pageTitle: { type: String, initial: true },
pageContent: { type: Types.Html, wysiwyg: true, height: 400 },
seoTitle: { type: String },
seoKeywords: { type: String },
seoDescription: { type: String },
isActive: { type: Types.Boolean }
});
Page.defaultColumns = 'keyword, slug, menuTitle, isActive';
Page.register();
Also worth noting that you don't need to actually add the slug
field; it's automatically added to the schema for you because of your autokey
settings.
Upvotes: 11