MODX Community

classExtender handling select, radio, and checkbox input fields

I added some javascript to the form myExtraResourceFields to select the correct data reflected corresponding to the select, radio, or checkboxes and hide sections of the form based on the selections in the drop-downs, however, code appears above the manager header and it essentially breaks, and the form is not displayed until I remove all <script> tags…

What I want to accomplish.

  1. Get the data from database to reflect correctly in the mentioned form field types when editing a resource field that is extended with classExtender.
  2. Run javascript in myExtraResourceFields to hide parts of the form based on dropdown selection without breaking the manager and without getting code that is supposed to be hidden appearing above the manager.

The data is saving, but it’s no use if it’s not reflected correctly for users who want to edit that data via the mentioned input types. There must be a fundamental piece of information I’m ignorant of regarding running custom JS in the manager. Please educate me.

How do I handle multi-option input field types? Can I even put custom JS in the manager?

I have not actually tried what you’re attempting, but AFAIK, JS scripts are perfectly fine for use in MODX chunks and should work fine in the Manager. Are you sure your MyExtraResourceFields chunk does not contain a JS or HTML syntax error?

If that’s not the issue, you could try a plugin that calls regClientStartupScript($script) to inject the JS code (leaving out the script tags). I think OnDocFormPrerender might be the appropriate event for this.