How to add a form field to modx 2.2.14 manager pages

602 views Asked by At

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:

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?
2

There are 2 answers

1
Kristian Sandström On

Isn't input type="date" the answer to the first question? 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).

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. 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"

0
rogaldh On

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. If you'll choose this method you have to create a plugin which invokes on OnBeforeDocFormSave event. There you can redefine modResource editedon property from your TV and it will be saved in proper way. Also you may invoke another event(OnLoadWebDocument). There you can set modResource editedon property from you TV if you want to see correct data.

Pros:

  • fast calendar integration to the one of modResource's tab
  • 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

Another method is more complicated (you need skills in ExtJS). Create plugin which invokes on OnDocFormPrerender event. You can add JS to the modResource page there. 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. And of course you need events from first method for loading and updating editedon value. 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

P.S. You can view Xlexicon github repo. There you can find example of rendering new tab and manipulation with modResource properties. Also you can check modAvatar extra for MODX. There is an example of manupulation with existing tab.