扩展数组模式编辑器



是否可以在不覆盖数组模式的情况下扩展数组模式对话框.js(apostrophe-schemas/public/js)?

我正在尝试在全局模块中创建一个链接数组,为此我创建了:

...
name: 'links',
label: 'Links',
type: 'array',
titleField: 'title',
schema: [{
name: 'title',
label: 'Title',
type: 'string'
}, {
name: 'url',
label: 'Url',
type: 'url'
}, {
name: '_page',
label: 'Page',
type: 'joinByOne',
withType: 'apostrophe-page',
idField: 'pageId',
filter: {
projection: {
title: 1,
slug: 1
}
}
}]
...

现在我想设置标题字段并禁用 url 字段(如果页面是 选择。或者使用标题和网址字段。 如果我注册这样的脚本:

apos.define('apostrophe-array-editor-modal', {
extend: 'apostrophe-modal',
source: 'arrayEditor',
...
});

我覆盖了原始数组模态.js,但我只想注册一个更改处理程序并在保存之前检查输入。

我的目标是管理员可以在全局部分中编辑的(页脚/静态)链接列表,我可以在多个页面中使用它们。

谢谢!

我的建议是为每个链接制作某种type字段,编辑器可以在内部页面连接和外部URL之间进行选择。

select架构字段具有一个showFields参数,该参数可以根据所做的选择隐藏/显示架构表单的各个部分,请查看此处的文档 http://apostrophecms.org/docs/tutorials/getting-started/schema-guide.html#code-select-code

您的代码将如下所示

name: 'links',
label: 'Links',
type: 'array',
titleField: 'title',
schema: [{
name: 'title',
label: 'Title',
type: 'string'
}, {
name: 'linkType',
type: 'select',
label: 'Type',
choices: [{
label: 'External',
value: 'external',
showFields: ['url']
}, {
label: 'Internal',
value: 'internal',
showFields: ['_page']
}]
}, {
name: 'url',
label: 'Url',
type: 'url'
}, {
name: '_page',
label: 'Page',
type: 'joinByOne',
withType: 'apostrophe-page',
idField: 'pageId',
filter: {
projection: {
title: 1,
slug: 1
}
}
}]

在模板中,您始终可以检查linkType的值以做出标记决策。

最新更新