简体   繁体   English

如何将表单字段添加到modx 2.2.14管理器页面

[英]How to add a form field to modx 2.2.14 manager pages

I'm trying to add the editiedon field to the modx manager pages so my users can edit the value using this bit of documentation as a start point: 我正在尝试将editiedon字段添加到modx管理器页面,以便我的用户可以使用以下文档作为起点来编辑值:

http://rtfm.modx.com/revolution/2.x/case-studies-and-tutorials/adding-custom-fields-to-manager-forms http://rtfm.modx.com/revolution/2.x/case-studies-and-tutorials/adding-custom-fields-to-manager-forms

Which does work, but: 哪个有效,但是:

  • how can I make that a date/time field? 如何将其设置为日期/时间字段?
  • how can I place it in the settings tab of the given resource? 如何将其放置在给定资源的“设置”标签中?

Isn't input type="date" the answer to the first question? input type="date"是否是第一个问题的答案? I'm not sure how you would do the second part, unless you managed to get the rendered content and splice it in there somehow (unless theres som hidden specified method). 我不确定您将如何做第二部分,除非您设法获取了呈现的内容并以某种方式将其拼接到了其中(除非som隐藏了指定的方法)。

Otherwise, you could always solve it with regular form customization. 否则,您始终可以通过常规表单自定义来解决它。 You'll want to create a TV of type Date, and give it a custom default data through a snippet, that just fetches the current resources editedon value. 您将要创建一个类型为Date的电视,并通过一个片段为其提供自定义默认数据,该片段仅获取当前资源editedon值。 I guess you only need to update the resource/update form set. 我猜您只需要更新资源/更新表单集即可。 Under the template variables tab of the set, make sure your TV is connected and change the region value of it to "modx-resource-settings" 在该集的模板变量标签下,确保已连接电视并将其区域值更改为“ modx-resource-settings”

There are two different ways which have their own pros & cons. 有两种方法各有优缺点。

At first you can use template variable with Date type. 首先,您可以使用日期类型的模板变量。 It gives you correct ExtJS component for dates and you'll see calendar in TV's tab. 它为您提供了正确的ExtJS组件日期,您将在TV选项卡中看到日历。 If you'll choose this method you have to create a plugin which invokes on OnBeforeDocFormSave event. 如果选择此方法,则必须创建一个在OnBeforeDocFormSave事件上调用的插件。 There you can redefine modResource editedon property from your TV and it will be saved in proper way. 在那里,您可以从电视上重新定义modResource editedon属性,它将以正确的方式保存。 Also you may invoke another event( OnLoadWebDocument ). 您也可以调用另一个事件( OnLoadWebDocument )。 There you can set modResource editedon property from you TV if you want to see correct data. 如果要查看正确的数据,可以在电视上设置modResource editedon属性。

Pros: 优点:

  • fast calendar integration to the one of modResource's tab 将日历快速集成到modResource的选项卡之一
  • you can use Form Customization for security reasons. 您可以出于安全原因使用表单自定义。 It's rather easy and from the box. 这很容易,而且很简单。

Cons: 缺点:

  • Additional TV which complicates modResource updating process a little bit 额外的电视使modResource更新过程变得有些复杂

Another method is more complicated (you need skills in ExtJS). 另一种方法更复杂(您需要使用ExtJS的技能)。 Create plugin which invokes on OnDocFormPrerender event. 创建在OnDocFormPrerender事件上调用的插件。 You can add JS to the modResource page there. 您可以在此处将JS添加到modResource页面。 Your scripts should render new custom tab to the document where you can add your special field with calendar. 您的脚本应在文档中呈现新的自定义标签,您可以在其中添加日历的特殊字段。 So there is special ExtJS component in MODX for these purposes. 因此,出于这些目的,MODX中有一个特殊的ExtJS组件。 And of course you need events from first method for loading and updating editedon value. 当然,您需要第一种方法中的事件来加载和更新editedon值。 Also you can just render special field to the existing tab instead of creating new tab and rendering your custom field to it. 您也可以仅将特殊字段呈现给现有选项卡,而无需创建新选项卡并将其自定义字段呈现给它。

Pros: 优点:

  • you don't need TV anymore 你不再需要电视了
  • it's flexible 它很灵活

Cons: 缺点:

  • it's more complicated and takes time 比较复杂,需要时间

PS You can view Xlexicon github repo . PS您可以查看Xlexicon github存储库 There you can find example of rendering new tab and manipulation with modResource properties. 在这里,您可以找到渲染新标签和使用modResource属性进行操作的示例。 Also you can check modAvatar extra for MODX. 您也可以为MODX检查modAvatar extra There is an example of manupulation with existing tab. 有一个使用现有选项卡进行操作的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM