Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby Rails - optional form input shown conditional on checkbox
    primarykey
    data
    text
    <p>I am working on a dynamic form input display where if the users clicks something to show "advanced options" in the form, the input vectors will be displayed, but otherwise (the default) they will not be shown. I have the following pieces in my form partial:</p> <p>UPDATED 1x:</p> <pre><code>&lt;div class="form-inputs"&gt; &lt;%= f.input :message, label: 'Write message'%&gt; &lt;/div&gt; &lt;div class="form-inputs"&gt; &lt;%= f.check_box :advanced, {}, :id =&gt; "advancedbox" %&gt; &lt;/div&gt; &lt;div class="form-inputs" id="advancedopts" style="display:none;"&gt; &lt;%= f.input :startdatetime, label: 'Specify', :as =&gt; :datetime_picker %&gt; &lt;%= f.input :expirationdatetime, label: 'Specify', :as =&gt; :datetime_picker %&gt; &lt;/div&gt; </code></pre> <p>And the JS in the head of the form partial:</p> <p>UPDATED 1x:</p> <pre><code>&lt;head&gt;&lt;script type="text/javascript"&gt; var checkbox = document.getElementById('advancedbox'); checkbox.onchange = function() { if (checkbox.checked) { document.getElementById("advancedopts").style.display = "block;"; } else { document.getElementById("advancedopts").style.display = "none;"; } } &lt;/script&gt;&lt;/head&gt; </code></pre> <p>I took the inspiration for this from the following post: <a href="https://stackoverflow.com/questions/10322444/show-rest-of-a-form-if-a-checkbox-is-ckecked-in-ruby-on-rails">show rest of a form if a checkbox is ckecked in ruby on rails</a></p> <p>But I cannot get it to work: the checkbox shows, but clicking it on or off does not show my advanced form inputs. Can anyone help me debug?</p> <p>Thanks!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload