Sunday, 12 March 2017

How to reorder fields in Keystone's Admin UI

I'm trying to make Keystone into a CMS. So, I need models for Article, Category, ImagePage, AttachmentPage and so on. Every model I mentioned has a subset of common fields like: title, content, meta: {title, description, keywords} and so on.

In Keystone a model is constructed like this:

Article.add(fieldsCollectionObject)

so I defined the common fields in external file:

var T = require('keystone').Field.Types;

module.exports = {
    title: { type: T.Text, required: true },
    content: { type: T.Html, wysiwyg: true, height: 400 },
    meta: {
        title: { type: T.Text },
        desc: { type: T.Textarea, height: 50 },
        keywords: { type: T.Text },
    },
    publishedDate: { type: T.Date, index: true, dependsOn: { state: 'published' } },
    state: { type: T.Select, options: 'draft, published, archived', default: 'draft', index: true },
};

and having require'd it in model's file I do:

const _ = require('lodash');
const pageDef = require('./common/Page.js');
const keystone = require('keystone');
const T = keystone.Field.Types;

<...>

Article.add(_.defaultsDeep({
    brief: { type: T.Html, wysiwyg: true, height: 150 },
    category: { type: T.Relationship, ref: 'Category', many: false, collapse: true },
    tags: { type: T.Relationship, ref: 'Tag', many: true },
}, defs.authored, pageDef));

Now, the problem is with the order of fields in the Admin UI - unsurprisingly the brief, category and tags go before fields from pageDef. Is there any way to impose an order I want? Like title, brief, content, <the rest>?



via Forseti

No comments:

Post a Comment