# Undefined local variable or method when trying to hide elements with checkbox

**URL:** <https://discourse.openondemand.org/t/undefined-local-variable-or-method-when-trying-to-hide-elements-with-checkbox/4382>\
**Category:** Get Help\
**Created:** [July 23, 2025, 6:39pm UTC](https://discourse.openondemand.org/t/undefined-local-variable-or-method-when-trying-to-hide-elements-with-checkbox/4382 "2025-07-23T18:39:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kstine](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/kstine/32/2539_2.png) [@kstine](https://discourse.openondemand.org/u/kstine)\
**Post date:** [July 23, 2025, 6:39pm UTC](https://discourse.openondemand.org/t/undefined-local-variable-or-method-when-trying-to-hide-elements-with-checkbox/4382/1 "2025-07-23T18:39:27Z")

</div>

A sort of follow-up to this:

> [@Have options only show up when button is not clicked](https://discourse.openondemand.org/t/have-options-only-show-up-when-button-is-not-clicked/4372):
>
> Is it possible to have OOD only show and use form.yml options if a checkbox is unclicked? I’d like to make it so that if a user checks a “use entire node” button, it’ll send --exclusive to the submit.yml (and the script.sh.erb). But if it’s unchecked, it would show memory, cpus, and gpus to be requested (and send those values to the script.sh.erb). Is this possible? Or would I need to set up two apps, one for --exclusive and one without?

I have a check box hiding elements currently implemented in my form.yml:

```auto
m_exclusive:
    widget: "check_box"
    label: "Use entire node"
    html_options:
      data:
        hide-m-cpus-when-checked: true
        hide-m-mem-when-checked: true
        hide-m-gpus-when-checked: true
        data-set-m-cpus: "--exclusive"
        data-set-m-mem: ""
        data-set-m-gpus: ""

```

My submit.yml looks like the following:

```auto
native:
    - "-J"
    - "<%= m_name %>"
    - "-N"
    - "1"
    - "--mem"
    - "<%= m_mem %>G"
    - "-c"
    - "<%= m_cpus %>"
    - "-G"
    - "<%= m_gpus %>"

```

How do I make it so that if a user selects the `m_exclusive` checkbox that it will only send `--exclusive`?

---

<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:** [July 23, 2025, 7:18pm UTC](https://discourse.openondemand.org/t/undefined-local-variable-or-method-when-trying-to-hide-elements-with-checkbox/4382/2 "2025-07-23T19:18:53Z")

</div>

I don’t think checkboxes have support for `data-set` directives yet.

I think you need to handle this in the `submit.yml.erb`. Something like this should do.

```erb
<%-
  args = ["-J", m_name, "-N", "1", "--mem", "#{m_mem}G", "-c", m_cpus, "-G", m_gpus]

  args.concat(["--exclusive"]) if m_exclusive == 1
-%>

script:
  native:
  <%- args.each do |arg| %>
    - "<%= arg %>"
  <%- end %>

```

Though note that I don’t exactly recall how checkboxes are passed - i.e., as 1 and 0 or true and false and so on. I’m pulling that from memory without checking how it actually works.

---

<div class="post-metadata">

**Author:** ![kstine](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/kstine/32/2539_2.png) [@kstine](https://discourse.openondemand.org/u/kstine)\
**Post date:** [July 24, 2025, 4:00pm UTC](https://discourse.openondemand.org/t/undefined-local-variable-or-method-when-trying-to-hide-elements-with-checkbox/4382/3 "2025-07-24T16:00:31Z")

</div>

There’s something odd going on with the `--mem` portion as after adding the the args script, sbatch keeps giving the following in OOD:

```auto
sbatch: error: Invalid --mem specification

```

The `job_script_options.json` file from the refused job shows the following when the `m_exclusive` checkbox is checked:

```auto
"native": [
    "-J",
    "worker",
    "-N",
    "1",
    "--mem",
    "G",
    "-c",
    "",
    "-G",
    ""

```

It looks like it’s still passing through the hidden options?

---

<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:** [July 24, 2025, 4:28pm UTC](https://discourse.openondemand.org/t/undefined-local-variable-or-method-when-trying-to-hide-elements-with-checkbox/4382/4 "2025-07-24T16:28:12Z")

</div>

🤦‍♂️ yes it seems like you need extra logic there `if m_exclusive == 1`

---

<div class="post-metadata">

**Author:** ![kstine](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/kstine/32/2539_2.png) [@kstine](https://discourse.openondemand.org/u/kstine)\
**Post date:** [July 24, 2025, 6:04pm UTC](https://discourse.openondemand.org/t/undefined-local-variable-or-method-when-trying-to-hide-elements-with-checkbox/4382/5 "2025-07-24T18:04:50Z")

</div>

I wrote out the following:

```auto
script:
  native:
    - "-J"
    - "<%= m_name %>"
    - "-N"
    - "1"
    <%- if m_exclusive == true %>
    - "--exclusive"
    <%- else %>
    - "--mem"
    - "<%= m_mem %>G"
    - "-G"
    - <%= m_gpus %>
    - "-c"
    - <%= m_cpus %>
    <%- end %>

```

Used your script as inspiration and it seems to be working fine!

**EDIT** : I swapped it for the following and it seems to work better, although still not very cleanly:

```auto
script:
  native:
    - "-J"
    - "<%= m_name %>"
    - "-N"
    - "1"
  <%- if m_exclusive = 1 %>
    - "--exclusive"
  <%- end %>
  <%- if m_exclusive = 0 %>
    - "--mem"
    - "<%= m_mem %>G"
    - "-G"
    - <%= m_gpus %>
    - "-c"
    - <%= m_cpus %>
  <%- end %>

```

---

<div class="post-metadata">

**Author:** ![kstine](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/kstine/32/2539_2.png) [@kstine](https://discourse.openondemand.org/u/kstine)\
**Post date:** [July 28, 2025, 6:42pm UTC](https://discourse.openondemand.org/t/undefined-local-variable-or-method-when-trying-to-hide-elements-with-checkbox/4382/6 "2025-07-28T18:42:13Z")

</div>

@jeff.ohrstrom Turns out the above doesn’t actually work. If you previously clicked the `m_exclusive` button, it still keeps the `--exclusive` in the job script options.

Example:

```auto
"native": [
    "-J",
    "worker",
    "-N",
    "1",
    "--exclusive",
    "--mem",
    "160G",
    "-G",
    1,
    "-c",
    32
  ]

```

It should be removing the `--exclusive` if unchecked, right?

---

<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:** [July 28, 2025, 6:59pm UTC](https://discourse.openondemand.org/t/undefined-local-variable-or-method-when-trying-to-hide-elements-with-checkbox/4382/7 "2025-07-28T18:59:38Z")

</div>

> [@kstine](#):
>
> `if m_exclusive = 0`

One single `=` is the assignment operator. You’re assigning m\_exclusive to 0 then evaluating that result as a boolean.

You need the equality operator `==`.

---

<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:** [January 24, 2026, 7:00pm UTC](https://discourse.openondemand.org/t/undefined-local-variable-or-method-when-trying-to-hide-elements-with-checkbox/4382/8 "2026-01-24T19:00:14Z")

</div>

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