# Dynamic behaviour with check box

**URL:** <https://discourse.openondemand.org/t/dynamic-behaviour-with-check-box/2060>\
**Category:** Get Help\
**Tags:** ondemand2\
**Created:** [May 10, 2022, 12:52pm UTC](https://discourse.openondemand.org/t/dynamic-behaviour-with-check-box/2060 "2022-05-10T12:52:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kickers56](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/kickers56/32/1088_2.png) [@kickers56](https://discourse.openondemand.org/u/kickers56)\
**Post date:** [May 10, 2022, 12:52pm UTC](https://discourse.openondemand.org/t/dynamic-behaviour-with-check-box/2060/1 "2022-05-10T12:52:58Z")

</div>

Hi,

Still learning and building on knowledge of ondemand. Such a useful portal for HPC

We are setting up ondemand 2.0.23 and have tried the dynamic behaviour of hiding fields in the form using the select widget (copying from the ansys template) which works great.

Is it possible to show and hide fields using a checkbox widget being checked and unchecked, and if so how should this be constructed in the form.yml.erb?

Thanks

---

<div class="post-metadata">

**Author:** ![gbyrket](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/gbyrket/32/894_2.png) [@gbyrket](https://discourse.openondemand.org/u/gbyrket)\
**Post date:** [May 10, 2022, 1:19pm UTC](https://discourse.openondemand.org/t/dynamic-behaviour-with-check-box/2060/2 "2022-05-10T13:19:15Z")

</div>

Hi Kickers. Welcome to the OnDemand Discourse thread.

You ask a great question. Out of the box, we do have what we call “Dynamic JavaScript (DynJS)”. However, it does not currently do what you are asking. The DynJS functionality works in conjunction with the drop-down elements. We do not have anything out of the box for the checkboxes. I would say you should be able to add your own JS functionality in form.yml.erb to control the hide/show functionality.  
You should be able to use something like the following at the top of the file.

```auto
<script type='text/javascript'>
 .... 
  Your JS code
 ....
</script>

```

Looking forward to seeing how this goes.

Thanks,  
-gerald

---

<div class="post-metadata">

**Author:** ![kickers56](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/kickers56/32/1088_2.png) [@kickers56](https://discourse.openondemand.org/u/kickers56)\
**Post date:** [May 10, 2022, 1:50pm UTC](https://discourse.openondemand.org/t/dynamic-behaviour-with-check-box/2060/3 "2022-05-10T13:50:34Z")

</div>

Thanks Gerald,

I shall have a play with setting something up using the JS, so I don’t need anything else (or to enable anything else) but to include the JS script at the top of the form.yml.erb?

---

<div class="post-metadata">

**Author:** ![gbyrket](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/gbyrket/32/894_2.png) [@gbyrket](https://discourse.openondemand.org/u/gbyrket)\
**Post date:** [May 10, 2022, 1:52pm UTC](https://discourse.openondemand.org/t/dynamic-behaviour-with-check-box/2060/4 "2022-05-10T13:52:57Z")

</div>

That should do it. I’ll add a feature request for this functionality. It will be down the road before we can get to it, but it seems that it may be something that we can make function like the Dynamic JS.

---

<div class="post-metadata">

**Author:** ![nobodyme](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/nobodyme/32/1307_2.png) [@nobodyme](https://discourse.openondemand.org/u/nobodyme)\
**Post date:** [October 17, 2022, 2:26pm UTC](https://discourse.openondemand.org/t/dynamic-behaviour-with-check-box/2060/5 "2022-10-17T14:26:35Z")

</div>

Hey @kickers56, were you able to get that working?  
I’m pretty new to Open OnDemand, would love to learn how to do it.

@gbyrket In many places I see, `batch_connect_session_context` identifier prefix used. Is that the default prefix that’s added to get the value of any field in `form.yml`?

Is there some documentation on how to go about adding this `form.js`, thanks.

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [November 4, 2022, 8:55pm UTC](https://discourse.openondemand.org/t/dynamic-behaviour-with-check-box/2060/6 "2022-11-04T20:55:32Z")

</div>

> [@nobodyme](#):
>
> @gbyrket In many places I see, `batch_connect_session_context` identifier prefix used. Is that the default prefix that’s added to get the value of any field in `form.yml`?

Yes unless you use the `id` field in the `form.yml`. Though if you do use `id` the dynamic javascript we ship with won’t work.

> [@nobodyme](#):
>
> Is there some documentation on how to go about adding this `form.js`, thanks.

It’s fairly simple - just drop a `form.js` in the root directory of the app (as a sibling to `form.yml` and `manifest.yml`) and it’ll load as a part of the HTML. (you’ll see a lot of examples execute all their functionality when the window is ready)

Here’s an older javascript file from one of our apps, though I can’t find any example we have where we interact with check boxes.

> <https://github.com/OSC/bc_osc_rstudio_server/blob/v0.18.0/form.js>

@kickers56 check box functionality is going to be a while because I had to add the feature to the upstream project that builds our forms. So it may be a while before it comes to Open OnDemand.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/osc/original/2X/b/bae70bd0ed39a3ae769c2108155f4cb3e9da8385.png) [@system](https://discourse.openondemand.org/u/system)\
**Post date:** [May 3, 2023, 8:55pm UTC](https://discourse.openondemand.org/t/dynamic-behaviour-with-check-box/2060/7 "2023-05-03T20:55:43Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
