Keystone.js admin interface - no form fields

I created a model 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: 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 to generate a list of objects and a form to create those objects. But the form has no fields.enter image description here

What am I doing wrong? Or what else should I do to get a form with all fields?

+3


source to share


1 answer


Basically you don't see any fields because you have the option initial

set to false

for all of them.

initial

the default is used false

, except for the "name" field, that is, the default is an outline field name

or path that matches the mapping specified by Keystone for name

, in your case menuTitle

.

So normally your field menuTitle

will render, expect you to explicitly tell it not with customization initial: false

.



To display the fields, just set the ones you want initial: true

, for example:

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();

      

It's also worth noting that you don't need to add a field slug

; it is automatically added to the schema for you due to your settings autokey

.

+10


source







All Articles