Grav-plugin-admin: 条件字段 - 将条件设置为其他/同级字段

创建于 2018-08-24  ·  5评论  ·  资料来源: getgrav/grav-plugin-admin

在模板的蓝图文件中,我想使用转发器/列表字段,
有一个带有选项的选择字段,
和条件字段评估用户选择的选项以相应地显示字段。

我想在长文章中使用它,用户可以在其中添加/切换不同类型的组件

如何将条件设置为选择字段的值(重复)?
就像现在的代码一样,只有选择是可见的,条件不起作用。

        header.field.selection:
          type: list
          style: vertical
          label: Repeater/list with conditional field selection
          fields:
            .select: # this select sets the boolean for the conditional fields
              type: select
              size: long
              classes: fancy
              label: Select the type of field you would like to add
              options:
                tinymce: Textarea
                slideshow: Slideshow
                testimonial: Testimonial
                video: Video
            .tinymce:
              type: conditional # if Textarea was selected render the tinymce fields
              condition: "header.field.selection.select is same as('tinymce') ? 'true' : 'false'"
              fields: 
                .fieldName:
                  type: text
                  label: Tinymce
            .slideshow:
              type: conditional # if slideshow was selected render the slideshow fields
              condition: "header.field.selection.select is same as('slideshow') ? 'true' : 'false'"
              fields: 
                .fieldName2:
                  type: text
                  label: Slideshow
            .testimonial:
              type: conditional # if testimonial was selected render the testimonial fields
              condition: "header.field.selection.select is same as('testimonial') ? 'true' : 'false'"
              fields: 
                .fieldName3:
                  type: text
                  label: Testimonial
            .video:
              type: conditional # if video was selected render the video fields
              condition: "header.field.selection.select is same as('video') ? 'true' : 'false'"
              fields: 
                .fieldName4:
                  type: text
                  label: Video
question

所有5条评论

条件字段不是基于其他字段“实时”工作的东西,它只是可以在服务时执行 PHP 函数并做出决定。 其他任何事情都需要 Javascript 才能运行。

谢谢鲁克斯特。

我设法制作了一个“灵活内容字段”**(如 Wordpress 中的高级自定义字段)。 你可以在这里看到代码

** 定义子字段组(布局)并添加、编辑和重新排序它们以创建高度定制的内容!

很想在 Form 插件中看到这样的核心字段 :) PR 也许??

@rhukster
已为分支“功能/灵活表单字段”发出拉取请求。
地位:

  • 字段选择模板可用。 添加的字段正在正确保存和加载。
  • Js & CSS 还需要添加。
  • 添加了 example-fieldselection.yaml。

我确实需要一些帮助:

  • 字段的排序没有保存在 frontmatter 中。

tnx

(我在 slack 频道上是 'genenenenaam')

@rhukster

对“列表项的排序”和字段模板“list.html.twig”的名称有一些依赖性吗?

我做了一个测试,它似乎:

  • 如果您在“列表”文件夹所在的同一级别上创建一个新文件夹“字段选择”。
  • 复制文件“list.html.twig”,将其重命名为“fieldselection.html.twig”并将其放在“fieldselection”文件夹中。
  • 如果您现在制作一个使用“列表”字段类型的蓝图,但您为其指定了“字段选择”类型。
    (这应该没有区别,因此两种类型具有相同的代码内容)
  • 重新排序对“fieldselection”类型不起作用,但对“list”类型有效。
    (与删除项目相同)

我相信这个问题的答案可以解决我与新功能当前状态的问题。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

darkroastcreative picture darkroastcreative  ·  4评论

CoDanny picture CoDanny  ·  3评论

orasik picture orasik  ·  6评论

ritchiedalto picture ritchiedalto  ·  6评论

coolemur picture coolemur  ·  3评论