0

是否可以在不覆盖 array-modal.js (撇号-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 字段。或者使用标题和 url 字段。如果我注册这样的脚本:

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

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

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

谢谢!

4

1 回答 1

0

我的建议是为每个链接创建某种type字段,让编辑在内部页面加入和外部 URL 之间进行选择。

select架构字段有一个showFields参数,可以根据所做的选择隐藏/显示架构表单的一部分,请在此处查看文档http://apostrophecms.org/docs/tutorials/getting-started/schema-guide.html#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以做出标记决策。

于 2017-07-05T14:53:27.133 回答