northernPenguin
Scholar

How to set value of a yes/no or dropdown based on value of another control (responsive form)

Jump to solution

I would like know how to have the SharePoint 2019 responsive form respond to the change in value of a dropdown control to update the value of another control, specifically of the yes/no or dropdown (with Yes and No as options) type.

 

In responsive mode, it doesn't seem to support custom JavaScript (as classic would).  I found 1 rule type that sets the value of a single line text box based on a dropdown, but I don't want the target to be free-form text, rather something selectable like yes/no or a dropdown.

0 Kudos
Reply
4 Replies
Aleximo
Contributor

Re: How to set value of a yes/no or dropdown based on value of another control (responsive form)

Jump to solution

hey @northernPenguin ,

 

as far as I know it is not possible to do that in responsive forms.

0 Kudos
Reply
MegaJerk
Collaborator

Re: How to set value of a yes/no or dropdown based on value of another control (responsive form)

Jump to solution

Before I give you the answer to this, I really want to stress that while it *can* be done, it is NOT supported and is unorthodox.

It could break during an update.

It could break because Nintex decides they don't want people doing it.

It could break for any number of reasons!

Be aware that solving the problem this way could lead to a functionality that is, essentially, undocumented and hidden from anyone else who encounters this work at a later date!

 

Alright. Warnings out of the way, here is some context. Because the Rule System of a form is essentially just a place where you're piecing together little snippets of code (or text that gets compiled into code when it's served to you proper), you can actually use javascript inside of it outright. This is why you can use stuff like || and && (logical or, and logical and) inside of it without needing to use the runtime or() / and() functions that they give you.

 

To read more about how the Rule system works in detail, please see my article on the matter here: https://community.nintex.com/t5/Community-blogs/Breaking-The-Rules-A-Dive-Into-The-Nintex-Forms-Rule...

 

Here is a Responsive Form with a Drop Down Choice Control next to a Yes / No Control:

MegaJerk_0-1646406008723.png

 

The Controls are Configured as such

 

Choice Control:

MegaJerk_1-1646406070450.png

 

Yes / No Control:

MegaJerk_2-1646406079150.png

 

Selecting the Yes/No Control, I am going to add a Rule to it

MegaJerk_3-1646406276224.png

 

Then, in the order shown, rename the rule, set the rule to disable, and then click on the formula editor:

MegaJerk_4-1646406304147.png

 

Inside of the Formula Builder goes the following code:

(function(formControlCall, dropDown){
  var formControlID = formControlCall.split("'")[1] || "";
  var targetControl = sourceContext.find("[formcontrolid='" + formControlID + "'].nf-filler-control").find("[formcontrolid][id]");
  targetControl.prop("checked", dropDown.toLowerCase() === "alright");
  return false;
}("{Control:Self}", control_DropDown))

 

As shown, you need to replace the text of *control_DropDown* with the NAMED REFERENCE of the dropdown control in question. Because I named my dropdown choice control to "control_DropDown", I erase the word *control_DropDown* near the end of my code and replace it by double clicking the Named Reference. If you did it correctly, it should be in red as I show here:

MegaJerk_5-1646406497714.png

 

Now when we launch the form we can see that whenever we select the "Alright" option from the Dropdown, the Yes/No control is checked:

MegaJerk_6-1646406964246.png

 

MegaJerk_7-1646406971904.png

 

MegaJerk_8-1646406978467.png

 

All that said, this doesn't prevent someone from just changing the checkbox to any particular value they want. If you'd rather lock it down, then you can simply go back to your rule, and change the return value from false to true:

MegaJerk_9-1646407124102.png

 

Now the Yes / No Control is *always* disabled, but can still be toggled by our code:

MegaJerk_10-1646407186454.png

 

I hope that this has helped to build a better understanding of the Rule System and what can be done with a little code. Let me know if you need additional help or if this has solved it.

 

Additionally if you would like an explanation of how that code works, let me know. 

 

 

 

 

Reply
northernPenguin
Scholar

Re: How to set value of a yes/no or dropdown based on value of another control (responsive form)

Jump to solution

Thanks a lot, that's really neat!  I hadn't encountered the ability to put code directly into the formulas (although I have been using && and || without knowing that was why it works).  I've bookmarked the article you shared and will read through it sometime for more ideas.

 

I did come up with a separate solution that suits my current needs in this situation (and also is Nintex-"safe"), which I'll describe as follows for anyone that wants another solution:

 

I have the dropdown control and Yes/No control, plus added an additional calculated control.  Rather than have the Yes/No control (still named Approval Required) connected to the Approval Required column as it was before, I have the calculated control (named Calc Approval Required) hooked to the AR col.  In the calc. control, I put a formula like this:

If(equals([dropdown control name], "[dropdown choice that needs Yes/No as No]"), false, Approval Required)

Here I have false b/c I found from trial and error that Yes/No actually returns true/false.

 

Then after confirming in Preview that this works, add a hide always rule to the calc. control, and a rule to hide the Yes/No box when the dropdown has the particular value (plus a rule on the Yes/No box to make a selection required when the dropdown doesn't have the particular value).

 

So while this doesn't directly solve the problem as stated (which is to control the Yes/No box directly), I get a value saved on Approval Required I can use in the workflow, that will be false when the dropdown has the particular value, and the value of the Yes/No box any other time (which is really what I needed functionally).

Reply
MegaJerk
Collaborator

Re: How to set value of a yes/no or dropdown based on value of another control (responsive form)

Jump to solution

good to see that you have solved it, and in a safer way! 

 

Don't forget to mark your answer as the solution to this problem. 

0 Kudos
Reply