# Implementing a case statement in form.yml.erb

**URL:** <https://discourse.openondemand.org/t/implementing-a-case-statement-in-form-yml-erb/2306>\
**Category:** Get Help\
**Tags:** question\
**Created:** [October 7, 2022, 5:40pm UTC](https://discourse.openondemand.org/t/implementing-a-case-statement-in-form-yml-erb/2306 "2022-10-07T17:40:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![emily.dragowsky](https://avatars.discourse-cdn.com/v4/letter/e/c68b51/32.png) [@emily.dragowsky](https://discourse.openondemand.org/u/emily.dragowsky)\
**Post date:** [October 7, 2022, 5:40pm UTC](https://discourse.openondemand.org/t/implementing-a-case-statement-in-form-yml-erb/2306/1 "2022-10-07T17:40:11Z")

</div>

I want to assign the appropriate tensorflow for the JupyterLab module selected.  
I’ve tried using the ‘data-options-for-modules-JupyterLab/3.1.6: false/true’ approach in form.yml without any success.

So it occured to try and step up to the extended ruby usage in our form.yml (form.yml.erb). So, is this a good idea? If it’s not a bad idea, should the following implement what I’m looking for? The following currently breaks my ood session

> 32 modules:  
> 33 label: “Select module for Jupyter version”  
> 34 widget: select  
> 35 options:  
> 36 - [“JupyterLab/3.1.6”, “JupyterLab/3.1.6-GCCcore-11.2.0”]  
> 37 - [“JupyterLab/3.2.8”, “JupyterLab/3.2.8-GCCcore-10.3.0”]  
> 38 extra\_jupyter\_args: “”  
> 39 accessmod:  
> 40 \<%- case modules  
> 41 when “Jupyter/3.1.6”  
> 42 value: “TensorFlow/2.7.1-foss-2021b-CUDA-11.4.1”  
> 43 else  
> 44 value: “TensorFlow/2.6.0-foss-2021a-CUDA-11.3.1”  
> 45 end  
> 46 %\>

---

<div class="post-metadata">

**Author:** ![emily.dragowsky](https://avatars.discourse-cdn.com/v4/letter/e/c68b51/32.png) [@emily.dragowsky](https://discourse.openondemand.org/u/emily.dragowsky)\
**Post date:** [October 7, 2022, 9:02pm UTC](https://discourse.openondemand.org/t/implementing-a-case-statement-in-form-yml-erb/2306/2 "2022-10-07T21:02:56Z")

</div>

All I really want to do is use the ‘data-option-for’ feature, which works sometimes, and not others. The implementation that works well is the first quoted block. For the choice of partition, the available node\_type is restricted to those that make sense. In addition, the ‘data-hide’ method is used to suppress the number of gpus when the partition does not support gpu nodes. In the second block, I try to apply the same idea to module selection, where my module system has EasyBuild toolchains – and I don’t want to have requests to mix toolchains at load time. Why that is not working is beyond my capabilities at the moment.

> 69 num\_gpu:  
> 70 label: “GPU [1 or 2] – optional field, leave 0 unless asking for node with gpus”  
> 71 widget: “number\_field”  
> 72 required: false  
> 73 value: 0  
> 74 min: 0  
> 75 max: 2  
> 76 node\_type:  
> 77 label: “Node Type: batch, gpu for research; class(c) - specific course groups only)”  
> 78 widget: select  
> 79 options:  
> 80 - [ “batch”, “batch”,  
> 81 data-hide-num-gpu: true ]  
> 82 - [“gpu”, “gpu”]  
> 83 - [“aisc”, “aisc”]  
> 84 type\_constraint:  
> 85 label: “Node Features”  
> 86 help: |  
> 87 - Uses the ‘-C’ flag to select gpu or cpu node capabilities  
> 88 widget: select  
> 89 options:  
> 90 - [ “Next available cpu node”, “icosa192gb|icosa256gb”,  
> 91 data-option-for-node-type-gpu: false,  
> 92 data-option-for-node-type-aisc: false,  
> 93 ]  
> 94 - [ “Pioneer: icosa192gb”, “icosa192gb”,  
> 95 data-option-for-node-type-gpu: false,  
> 96 data-option-for-node-type-aisc: false,  
> 97 data-max-job-mem-for-type-constraint-icosa192gb: 186, ]  
> 98 - [ “Pioneer: icosa256gb”, “icosa256gb”,  
> 99 data-option-for-node-type-gpu: false,  
> 100 data-option-for-node-type-aisc: false,  
> 101 data-max-job-mem-for-type-constraint-icosa192gb: 250, ]  
> 102 - [ “Next available gpu 2080, p100 or v100 node”, “gpu2080|gpup100|gpu2v100”,  
> 103 data-option-for-node-type-batch: false,  
> 104 data-option-for-node-type-aisc: false,]  
> 105 - [ “Pioneer: gpu2v100”, “gpu2v100”,  
> 106 data-option-for-node-type-batch: false,  
> 107 data-option-for-node-type-aisc: false,  
> 108 data-max-job-mem-for-type-constraint-gpu2v100: 188, ]  
> 109 - [ “Pioneer: gpup100”, “gpup100”,  
> 110 data-option-for-node-type-batch: false,  
> 111 data-option-for-node-type-aisc: false,  
> 112 data-max-job-mem-for-type-constraint-gpup100: 186, ]  
> 113 - [ “Pioneer: gpu2080”, “gpu2080”,  
> 114 data-option-for-node-type-batch: false,  
> 115 data-option-for-node-type-aisc: false,  
> 116 data-max-job-mem-for-type-constraint-gpu2080: 125, ]

And for the code working not, I’ve tried different attribute names, adjusting the single- vs double-quotes…i don’t see why this is failing to reduce the number of options presented, because the code above does just that. In producing the above code, I did not that the syntax requirements are pretty finicky, so perhaps there’s something obvious to someone else.

> 121 jupyter\_ver:  
> 122 label: “Select module for Jupyter version”  
> 123 widget: select  
> 124 options:  
> 125 - [‘6’, ‘JupyterLab/3.1.6-GCCcore-11.2.0’]  
> 126 - [‘8’, ‘JupyterLab/3.2.8-GCCcore-10.3.0’]  
> 127 # - [“JupyterLab/3.1.6”, “JupyterLab/3.1.6-GCCcore-11.2.0”]  
> 128 # - [“JupyterLab/3.2.8”, “JupyterLab/3.2.8-GCCcore-10.3.0”]  
> 129 # extra\_jupyter\_args: “”  
> 130 accessmod:  
> 131 label: “Choose Tensorflow to match the toolchain supporting JupyterLab”  
> 132 widget: select  
> 133 options:  
> 134 - [  
> 135 ‘TensorFlow/2.6.0-foss-2021a-CUDA-11.3.1’, ‘TensorFlow/2.6.0-foss-2021a-CUDA-11.3.1’,  
> 136 data-option-for-jupyter-ver-8: true,  
> 137 data-option-for-jupyter-ver-6: false  
> 138 ]  
> 139 - [  
> 140 ‘TensorFlow/2.7.1-foss-2021b-CUDA-11.4.1’, ‘TensorFlow/2.7.1-foss-2021b-CUDA-11.4.1’,  
> 141 data-option-for-jupyter-ver-6: true,  
> 142 data-option-for-jupyter-ver-8: false  
> 143 ]

---

<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:** [October 10, 2022, 3:17pm UTC](https://discourse.openondemand.org/t/implementing-a-case-statement-in-form-yml-erb/2306/3 "2022-10-10T15:17:20Z")

</div>

Can you attach the yml file directly to the topic? I think that may help a bit with all the formatting there.

There’s a lot to go through here - could you rephrase the problem statement a little simpler? I.e., `I want accessmod to change options for jupyter_ver`.

> [@emily.dragowsky](#):
>
> So it occured to try and step up to the extended ruby usage in our form.yml (form.yml.erb). So, is this a good idea?

Likely not - but if looks like you answered yourself. You need the `data-` options for javascript to update the page. All Ruby ERB is rendered server side - so it doesn’t create the dynamic behavior you want because that’s all client side javascript.

---

<div class="post-metadata">

**Author:** ![emily.dragowsky](https://avatars.discourse-cdn.com/v4/letter/e/c68b51/32.png) [@emily.dragowsky](https://discourse.openondemand.org/u/emily.dragowsky)\
**Post date:** [October 11, 2022, 7:51pm UTC](https://discourse.openondemand.org/t/implementing-a-case-statement-in-form-yml-erb/2306/4 "2022-10-11T19:51:41Z")

</div>

The goal is to use the dynamic form(js) such that the choice of jupyter version limits the options presented under accessmod. Lines 125-128 just reflect trying a short label (125-6) in the event it’s the label that is used as the case of the ‘data-option-for’.

I’ll try to remember how to attach a file.

---

<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:** [October 11, 2022, 8:02pm UTC](https://discourse.openondemand.org/t/implementing-a-case-statement-in-form-yml-erb/2306/5 "2022-10-11T20:02:30Z")

</div>

Cool. Drag and drop should work, but here’s this button too.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/osc/original/2X/e/e2427ad92768bfca27cdc8487f4b35a1386f64a9.png)

---

<div class="post-metadata">

**Author:** ![emily.dragowsky](https://avatars.discourse-cdn.com/v4/letter/e/c68b51/32.png) [@emily.dragowsky](https://discourse.openondemand.org/u/emily.dragowsky)\
**Post date:** [October 11, 2022, 8:22pm UTC](https://discourse.openondemand.org/t/implementing-a-case-statement-in-form-yml-erb/2306/6 "2022-10-11T20:22:31Z")

</div>

[notworking\_form.yml](https://discourse.openondemand.org/uploads/short-url/qBpMgiovxnLgoP0oCNull3GER7J.yml) (5.4 KB)  
[working\_form.yml](https://discourse.openondemand.org/uploads/short-url/oQnUCcGNjtjHzZIHEORxLPCgTPw.yml) (3.9 KB)

---

<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:** [October 14, 2022, 3:49pm UTC](https://discourse.openondemand.org/t/implementing-a-case-statement-in-form-yml-erb/2306/7 "2022-10-14T15:49:38Z")

</div>

There’s a bug on our side where we don’t like the `/` in your variable names (specifically `JupyterLab/3.1.6-...`).

Replace `JupyterLab/...` with `JupyterLab-...` and it should work.

```yaml
  jupyter_ver:
    label: "Select module for Jupyter version"
    widget: select
    options:
      - ['6', 'JupyterLab-3.1.6-GCCcore-11.2.0']
      - ['8', 'JupyterLab-3.2.8-GCCcore-10.3.0']
  accessmod:
    label: "Choose Tensorflow to match the toolchain supporting JupyterLab"
    widget: select
    options:
      - [
          'TensorFlow/2.6.0-foss-2021a-CUDA-11.3.1', 'TensorFlow/2.6.0-foss-2021a-CUDA-11.3.1',
          data-option-for-jupyter-ver-JupyterLab-3.2.8-GCCcore-10.3.0: false,
        ]
      - [
          'TensorFlow/2.7.1-foss-2021b-CUDA-11.4.1', 'TensorFlow/2.7.1-foss-2021b-CUDA-11.4.1',
          data-option-for-jupyter-ver-JupyterLab-3.1.6-GCCcore-11.2.0: false,
        ]

```

Then assuming you had something like this in your `script.sh.erb` you can make this replacement back to slashes:

```ruby
# script.sh.erb - replace 
# <%= jupyter_ver %>
# with
<%= jupyter_ver.gsub("JupyterLab-", "JupyterLab/") %>

```

---

<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:** [October 14, 2022, 4:12pm UTC](https://discourse.openondemand.org/t/implementing-a-case-statement-in-form-yml-erb/2306/8 "2022-10-14T16:12:31Z")

</div>

Also you don’t need to set `data-option-for` to `true`. Everything is an option for everything else by default. So you only need to set stuff to `false` to hide options.

```yaml
data-option-for-jupyter-ver-JupyterLab/3.1.6-GCCcore-11.2.0: true,

```

---

<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:56pm UTC](https://discourse.openondemand.org/t/implementing-a-case-statement-in-form-yml-erb/2306/9 "2022-11-04T20:56:04Z")

</div>

@emily.dragowsky I’ve fixed this bug in `2.0.29` which will be out sometime next week.

---

<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:56pm UTC](https://discourse.openondemand.org/t/implementing-a-case-statement-in-form-yml-erb/2306/10 "2023-05-03T20:56:43Z")

</div>

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