Bear Bibeault wrote:For the uninitiated, info on Reactive programming.
Thanks. I remember at work two years ago we had a hideously complicated web form. There was all of the usual input field validation, a few Ajax calls, eight or more conditionally hidden sections, and a few dozen input fields that were conditionally enabled based upon values in other fields.
We tried to develop it with a colossal set of 'if' statements, but it was a buggy and broken mess. Finally I gave up and started over with a giant JSON data structure. The main keys were the HTML IDs of every element on the page, and the keys linked to an array of HTML IDs of dependencies for hide or show (if any), then an array of HTML IDs for dependencies for enable/disable the field (if any), and then an array of custom functions to call when the value of the field changed for validation and Ajax calls and other custom computation (if any). Then we just attached a single event handler to the entire page that would traverse the JSON object and apply all detected changes based on the state of items, and then return the number of page elements that were changed by the event. If the result was 0, it stopped. If the result was greater than 0, it ran the event handler again to handle cascading changes.