Show/Hide input fields based on other input field selected in CMP using Migx

I’m working my way through a bunch of tutorials to build a CMP using migx to manage Popups on a website. I’m currently stuck on a scenario where I want to show/hide a “Cookie lifetime” input field if I select a “Cookie” in the “Popup type” selectbox. If I can figure this out, then I can do all the other conditional fields I want, but so far I can’t figure out anything.

I’ve seen this post, but can’t figure out how to get the result of the “Popup type” field to trigger the “Restrictive Condition (MODX tags)” element of the “Cookie lifetime” field.

I guess what I am asking is how do I get access the value of a Migx form field in a snippet so that I can update the Restrictive Condition value of a different field.

The content of the field “Restrictive Condition (MODX tags)” is only executed on the server when the Update-Windows is loaded.

If you want to show/hide a input field dynamically, when the value of a dropdown changes, you need a solution in Javascript.

I’m not sure if that is even possible with MIGX. The “Description is Code” field allows to add HTML-markup or <script>-tags to the form and could maybe be used for this purpose.

maybe, you can make use of the multiple different formtabs feature like here
Configurator-Version - MIGX.Varying layout-boxes | MODX Documentation

I was thinking of using this solution for the “Templating” of my popups, but I just wanted to tidy up some of the default settings of the popups to streamline the interface, so that there aren’t so many settings all at once on the page.

Thanks for the comments & feedback anyway. Always appreciated.

Ah, shame. Well I think I’ll go with a more basic solution for now (I need to deliver something sooner, rather than more/better later), and look into the javascript solution later.

Do you know if I went down a non-Migx CMP solution, would I be able to do it somehow? The non-Migx solution seems a lot more work to get it going, so I don’t want to go down that rabbit hole if it isn’t going to be possible.

Finally, thanks for your feedback and never-ending support on the forums, not only do you help the original poster, but I often glean lots of useful tid-bits and further knowledge reading your answers.

Sure, with your custom code you can add a listener to the combobox to show/hide other fields.

But if you want to do it “the MODX way”, then you have to learn Ext.js.
MODX uses an old version of Ext.js (3.4) and there aren’t many tutorials or examples available. You basically have to read the code of existing extras to learn how to do things.
So it may not be worth the effort.

You could also use a different JS Framework (like for example Vue.js) for the CMP, if you are familiar with one.