Setting a value to a hidden form variable

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.

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.

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.

No change when I moved the form.js out.

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.

form.txt (6.6 KB)

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).

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 (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…

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.

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

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.

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.

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:

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.

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.

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 (4.9 KB)

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.

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.