# Setting a value to a hidden form variable

**URL:** <https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048>\
**Category:** Get Help\
**Tags:** ondemand2, question\
**Created:** [October 25, 2023, 6:44pm UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048 "2023-10-25T18:44:31Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![rsand](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/rsand/32/743_2.png) [@rsand](https://discourse.openondemand.org/u/rsand)\
**Post date:** [October 25, 2023, 6:44pm UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/1 "2023-10-25T18:44:31Z")

</div>

I have a variable in a form that has the widget set to hidden\_field. It works to set a default value on the field attributes. I want to be able to set the variable from another variable with the data-set option. This is what I have in the form but the variable is not changing as the Account variable changes.

account:  
label: “Account”  
widget: select  
options:  
\<%- CustomAccounts.Accounts.each do |a| -%\>  
- [ “\<%= a %\>”, “\<%= a %\>”,  
data-max-num-cores: “\<%= CustomCores.Cores[a] %\>”,  
data-max-num-nodes: “\<%= CustomNodes.Nodes[a] %\>”,  
data-max-gpus: “\<%= CustomGpus.Gpus[a] %\>”,  
data-set-ntype: “\<%= CustomNtype.Ntype[a] %\>”  
]  
\<%- end -%\>

ntype:  
widget: hidden\_field  
value: “all”

and when I look at the source of the form I see:

\< option data-max-num-cores=“96” data-max-num-nodes=“9999” data-max-gpus=“96” data-set-ntype=“gpu” value=“gctest”\>gctest\</ option\>  
\< option data-max-num-cores=“” data-max-num-nodes=“10” data-max-gpus=“0” data-set-ntype=“all” selected=“selected” value=“open”\>open\</ option\>

which is what I expect but when I select the gctest account the value of ntype does not change.

---

<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 25, 2023, 8:34pm UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/2 "2023-10-25T20:34:01Z")

</div>

What you expect is what should happen. Indeed we even do the same in a few of our apps.

I’ll have to check into it and try to replicate. Off the top - your YAML (and the data attributes) looks OK so I’m really not sure why this would be the case.

This leads me to believe it’s something very simple that we’re overlooking - did you happen to set the `id` for any of these fields? Specifying the `id` can throw dynamic behavior off. I guess I’d also ask if you have any `form.js` that could conflict with this.

---

<div class="post-metadata">

**Author:** ![rsand](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/rsand/32/743_2.png) [@rsand](https://discourse.openondemand.org/u/rsand)\
**Post date:** [October 25, 2023, 9:32pm UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/3 "2023-10-25T21:32:09Z")

</div>

No id set on any variables. I do have a form.js script but it is for another variable. I could remove the form.js to see if that changes the results.

---

<div class="post-metadata">

**Author:** ![rsand](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/rsand/32/743_2.png) [@rsand](https://discourse.openondemand.org/u/rsand)\
**Post date:** [October 26, 2023, 1:46pm UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/4 "2023-10-26T13:46:21Z")

</div>

No change when I moved the form.js out.

---

<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 26, 2023, 2:08pm UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/5 "2023-10-26T14:08:39Z")

</div>

Can you share your whole form as a text file? I wonder if there’s something outside of what you’ve posted that’s affecting this.

---

<div class="post-metadata">

**Author:** ![rsand](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/rsand/32/743_2.png) [@rsand](https://discourse.openondemand.org/u/rsand)\
**Post date:** [October 26, 2023, 2:28pm UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/6 "2023-10-26T14:28:28Z")

</div>

[form.txt](https://discourse.openondemand.org/uploads/short-url/b73iZk6yXQ6DKRp5EAG95Ak1pJG.txt) (6.6 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 26, 2023, 8:21pm UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/7 "2023-10-26T20:21:47Z")

</div>

I am unable to replicate the issue. I had to modify the form slightly to accommodate for `CustomAccounts.Accounts.`, but it appears to work as you’d expect (it correctly sets the hidden field `ntype`.

What browser are you using? Also what version of OnDemand are you on? (I tested on 3.0.3).

---

<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 26, 2023, 8:25pm UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/8 "2023-10-26T20:25:23Z")

</div>

This is what i edited it, though I don’t think it’s any different than what you’ve provided. I specified the accounts in the same way that you’ve got them in the `option` output there.

[form.txt](https://discourse.openondemand.org/uploads/short-url/3Q3pkAxJKItzf9emtha5NTrXL9p.txt) (6.8 KB)

That said - maybe there’s some 3rd account that’s throwing this off when you select _it_. I could not replicate with these 2 accounts - `gctest` and `open`. Perhaps there’s a 3rd that I’m missing that’s the key to this issue…

---

<div class="post-metadata">

**Author:** ![rsand](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/rsand/32/743_2.png) [@rsand](https://discourse.openondemand.org/u/rsand)\
**Post date:** [October 27, 2023, 11:17am UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/9 "2023-10-27T11:17:56Z")

</div>

I am using firefox and we are on version 2.0.32 of OpenOndemand. There isn’t a 3rd account on my user just those two. Your version is basically the same as mine as far as I can see.

---

<div class="post-metadata">

**Author:** ![rsand](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/rsand/32/743_2.png) [@rsand](https://discourse.openondemand.org/u/rsand)\
**Post date:** [October 27, 2023, 11:50am UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/10 "2023-10-27T11:50:34Z")

</div>

I’ve changed setting the ntype to the account variable a and changing the name of ntype but I still get the same result.

---

<div class="post-metadata">

**Author:** ![rsand](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/rsand/32/743_2.png) [@rsand](https://discourse.openondemand.org/u/rsand)\
**Post date:** [October 27, 2023, 11:55am UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/11 "2023-10-27T11:55:56Z")

</div>

At this time I am not seeing how to do this without using javascript to set the variable which is what the data-set is using.

---

<div class="post-metadata">

**Author:** ![rsand](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/rsand/32/743_2.png) [@rsand](https://discourse.openondemand.org/u/rsand)\
**Post date:** [October 27, 2023, 12:01pm UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/12 "2023-10-27T12:01:02Z")

</div>

Maybe it is working. I made the variable just a text field and it changes. But I don’t see any change in the value of the variable in the html source. I’ll see if it works to control another variable that I need it for.

---

<div class="post-metadata">

**Author:** ![rsand](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/rsand/32/743_2.png) [@rsand](https://discourse.openondemand.org/u/rsand)\
**Post date:** [October 27, 2023, 12:08pm UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/13 "2023-10-27T12:08:41Z")

</div>

Yeah when I select the gctest account the ntype variable gets set to gpu but the node\_type variable isn’t getting set with the data-option-for-ntype-gpu:

---

<div class="post-metadata">

**Author:** ![rsand](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/rsand/32/743_2.png) [@rsand](https://discourse.openondemand.org/u/rsand)\
**Post date:** [October 27, 2023, 12:39pm UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/14 "2023-10-27T12:39:20Z")

</div>

Seeing that this is no longer an issue of the hidden variable getting set I’ll close this and work on the new issue. 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:** [October 27, 2023, 1:40pm UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/15 "2023-10-27T13:40:31Z")

</div>

Yea I think the behavior may have changed slightly with version 2.0 and 3.0.

That is - 3.0 accommodates this when 2.0 doesn’t quite do the trick. I think it’s an issue of propogating events which we updated in 3.0.

---

<div class="post-metadata">

**Author:** ![rsand](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/rsand/32/743_2.png) [@rsand](https://discourse.openondemand.org/u/rsand)\
**Post date:** [October 30, 2023, 12:19pm UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/16 "2023-10-30T12:19:37Z")

</div>

Ok I am trying this on my test server with OpenOndemand 3.0.3. The bc\_dynamic\_js is set to true. When I select the open account the rc\_partition and node\_type is set correctly but when I switch to the gctest account they do not change. I’ve verified the nodetype variable is set to gpu. I’ve included the form.yml.erb as form.txt. It seems that whichever account I have first in the account options that is what is setting the other two select fields.  
[form.txt](https://discourse.openondemand.org/uploads/short-url/7WFi18kCxeLX3jV5ZQklJuEtWoZ.txt) (4.9 KB)

---

<div class="post-metadata">

**Author:** ![rsand](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/rsand/32/743_2.png) [@rsand](https://discourse.openondemand.org/u/rsand)\
**Post date:** [October 30, 2023, 1:18pm UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/17 "2023-10-30T13:18:33Z")

</div>

I have found that if I manually change the nodetype variable then go and set the account to the type of node for that node type it works but only for that account/nodetype pair.

---

<div class="post-metadata">

**Author:** ![rsand](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/rsand/32/743_2.png) [@rsand](https://discourse.openondemand.org/u/rsand)\
**Post date:** [November 2, 2023, 11:24am UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/18 "2023-11-02T11:24:09Z")

</div>

I’ve found a different way of going about doing what I needed that mostly works with 2.0.23 by using a case statement where I select the account to set values and hide fields.

---

<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:** [April 30, 2024, 11:24am UTC](https://discourse.openondemand.org/t/setting-a-value-to-a-hidden-form-variable/3048/19 "2024-04-30T11:24:33Z")

</div>

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