【问题标题】:Extend array modal editor扩展数组模态编辑器
【发布时间】:2017-07-05 22:53:27
【问题描述】:

是否可以在不覆盖 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,但我只想注册一个更改处理程序并在保存之前检查输入。

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

谢谢!

【问题讨论】:

    标签: apostrophe-cms


    【解决方案1】:

    我的建议是为每个链接创建某种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 的值来做出标记决定。

    【讨论】:

    • 谢谢,这将解决我的问题。但是是否可以为一个模态对话框加载两个或多个 js 文件。或者是否可以为特定字段加载 js-file/s?
    • 不完全确定您要做什么,但您可以通过覆盖作品editor-modal.js 此处的文档apostrophecms.org/docs/tutorials/howtos/… 中的beforeShow 方法在作品的编辑器模式中加载自定义js >
    猜你喜欢
    • 2011-05-14
    • 1970-01-01
    • 2020-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-08
    • 1970-01-01
    相关资源
    最近更新 更多