Rule to hide based on value of control inside repeater?


Badge +8

Is there any way to hide a control if a control inside a repeater is selected? , I can hide it if a =="Nurse" but if I add another row and select "diet" in that control, value of the control (displayed in a calculated value) now looks like "Nurse;Diet" and any additional rows just add to that. I want to hide a control if Nurse is selected in any of those but I'm not really seeing a way to do so. Any ideas?


11 replies

Userlevel 5
Badge +14

I assume that you want to hide a Control outside of a Repeating Section, but use the controls that are inside of a Repeating Section to base your arguments off of. yes? 

If that's the case, then using the following code in a Formatting Rule should accomplish what you're trying to do: 

(function(repeaterControls, valueToHideOn){
  var matchExp = new RegExp(valueToHideOn, "gi");
  return repeaterControls.filter(function(controlValue){
    return controlValue.match(matchExp) !== null;
  }).length > 0;
}(referenceToTheRepeatingSectionControl, "Nurse"))

Note: Because I have used .match() instead of just testing for equality, this isn't a particularly strict rule. If you require it to be more strict, or you have a word appear as a substring to one of the values being processed, then it might be better to use: 

(function(repeaterControls, valueToHideOn){
valueToHideOn = valueToHideOn.toLowerCase();
  return repeaterControls.filter(function(controlValue){
    return controlValue.toLowerCase() === valueToHideOn;
  }).length > 0;
}(referenceToTheRepeatingSectionControl, "Nurse"))

Does this help you to solve your problem? 

Badge +7

Hi,

You can add a hidden calculated value inside repeating section and set value = "1" if a == "Nurse" and "0" if a != "Nurse".

Let's suppose that the name of the control is X.

Then add a calculated value named Y outside repeating section with formula = Sum(X).

Now if Y > 0 then hide your control.

BR,

Userlevel 5
Badge +14

use formatting rule with formula like

inArray(NamedControlFromRepeater,"Nurse")
Badge +8

I was thinking of doing something like this but the drop down I'm evaluating has 80+ options. That's a lot controls/rules to add.

Badge +8

This doesn't seem to work for me and I think it's because the control is a lookup. When I use this for a text field it works fine. 

Userlevel 5
Badge +14

Yo N J‌, are you trying to hide a control that is outside of the repeating section based on the selections made of controls that are inside the repeating section? 

Does this rule do what you're trying to do? 

Can you include a screenshot to maybe help me understand if I have it wrong? 

Badge +8

I promise I'm not ignoring you! I was looking over your post as you posted your second one happy.png 

I'll be honest, I tried the others first because they were a little quicker to attempt haha.

You're correct, I'm trying to hide controls outside of the repeater, based off a list lookup control inside the repeater.

Userlevel 5
Badge +14

After seeing Marian's rule, and now knowing what you're working with, I'd just use a modified version of: 

inArray(parseLookup(someLookup), "Nurse")

or, for a visual: 

215615_pastedImage_1.png

Badge +8

Ah ha! That works. Thanks Marian Hatala‌ and Megajerk

Userlevel 5
Badge +14

sure, lookup control makes a little difference.

since nmarples‌ already pointed you to a proper direction, take it as a little learning for you: always try to provide as much details as you can when you ask for help. the best is if you provide screenshots of your configuration, what output you get, what errors you are facing etc. sometimes changing of single checkbox setting which you might consider not being important might change the game happy.png

Badge +7

Even if 1000 options you are adding only one field with one condition like if Nurse then 1 else 0.

Reply