As mentioned in a previous thread, I'm testing RJS templates to see if they can help me meet some requirements for a project I'm about to start.
The goal is to generate forms that use AJAX to help the user understand what can be entered. In many cases, our forms have rules like "If Option A is selected then Text Field C can not be used."
So I put together a small test form with two text inputs and a radio- button set: one button labeled Yes and one button labeled No.
The requirements I'm trying to test are:
* When Yes is clicked, hide Element 2 * When No is clicked, display Element 2 * If an element is hidden, its label is hidden * When form is first rendered for editing, Element 2 is hidden if Yes is already selected.
I've gotten the first three down, but can't get number four.
Currently I'm using form_observer to watch for changes to my little form. And if those changes require an element to be hidden or shown, code in the RJS view file is handling that. But form_observer only fires when the form changes, not when it is first loaded.
I could write code in the _form partial to hide those fields when it's first building the form, but that's not very DRY. I'd have the element- hiding rules in both the _form partial and the RJS template.
I tried adding ":on => 'load'" to the form_observer, but that did not work. Also, creating a "periodically_call_remote" didn't seem to do what I wanted, either.
Any ideas?
Thanks for pitching in with all my recent questions.
Ian