About the calculation value to a hidden filed

HI Team,
i want to create a hidden value from the other field like
if year is <= 2009 then hidden value show " prevalent Case" and if year is >=2010 & year <=2017 then “Event Case” and if year is >=2018 then “New Case”.
Please help me about this, i am not a coder or app builder.

Thanks & Regards
Naveen

Hi Naveen

you want to create questions of the type “Label” and then type up the label you want to show up

then, on those label’s display conditions, you need to write a condition that returns “true” for when you want it to show up.

so, if you take out the year from the date in a hidden calculation, you can then use that calculation in the validation field of the label, and say something like
year_calc < 2010

here’s a link that gives off a few examples on working with date types
https://confluence.dimagi.com/display/commcarepublic/Calculations+with+Dates+and+Times

and here’s a link about display conditions in general (you can have display conditions for different things in different parts of CommCare)
https://confluence.dimagi.com/display/commcarepublic/Display+Conditions+Overview

if you wish the label to show up to the user, and to also prevent them from moving forward with that submission, just add the value “false()” in the label’s validation conditions. what this will do is tell the form that something is wrong, but only when that label shows up on the form.

HTH

Mazz

Hello @Mazz,

I am trying to implement a condition on a hidden field that stops the user from proceeding if the calculation in the hidden field doesn’t equal 100 but can’t seem to get it right.

i think this is because you have the single quotes around the 100
this tells commcare that it’s a text value, when your hidden value actually probably contains a number.

take the single quotes out and see if that works

I just took out the quotes but it still doesn’t restrict the user from moving on to the next set of questions.

I believe there should be a validation condition somewhere that tests if the hidden field validates to 100 then if not it then displays the validation message and restricts the user from proceeding.

Should that validation be in the hidden field itself on in the label that outputs the hidden field? This is my hidden field below:

so first things first:
is the lable you’re setting showing up at 100?

second thing: having a label pop up with a false() validation condition isn’t going to always hide the rest of the questions. what it will do however, is prevent the user from submitting the form.

if you want to show/hide questions, then the display condition should be inside those questions or inside a question list/group with that display condition. the label with “False()” validation condition will only prevent the mobile worker from submitting the form.

So i want the label to show up no matter what the calculation tends to so i have removed the display condition on the label.

Secondly, the present setup doesn’t restrict the user from submitting the form, i have just submitted two forms using the present setup.

Is it impossible to set a validation condition on a hidden field? I do not see anyway to evaluate my calculation in the hidden field

yes, you cannot have a validation condition on a hidden calculation.

that’s why you use a label with a false() validation condition.
you can remove the display condition to have it show up all the time, but keep the validation condition so that it stops them from submitting

no form can be submitted if there’s a response that violates the validation

@Mazz, sorry but it seems i am not understanding this properly. What would be the essence of having a false() validation in the label, if there is no where to place a validation that checks to ensure the hidden calculation evaluates to 100? See below

If i place false() as a validation on the label (as shown in the image above), then where do i place another validation condition that ensures that the hidden field calculation = 100?

There is no validation condition entry for the hidden field…

so in this case, in the validation condition of the label “overall percentage”, you can put pecentage_agg_markets = 100 or !=100 however you need it to be

so, will always show it, but will return a false value when the condition is broken. if the condition is not broken, it’ll return true and allow you to submit.

@Mazz, so this is what i have now

It seems not to work when tested on the web so let me test this on an android tablet and give a feedback.

yeah i just tried it and it didn’t work

you’ll need a label with the validation condition “False()” or “0” that only shows up when your hidden calculation is the value that you want to break the form “display condition: value != 100”

this label shows you your score “number to check against”

this one will show up if the calculated value “hidden calculation” is not 100. when it shows up, it won’t let you submit the form. if your score is 100, it’ll disappear and therefor you can submit your form

This is very weird. I am still able to submit forms even with this setup

So the label shows up and it still lets you move on?

that’s pretty odd. I do see a warning sign though do you think it might not be able to resolve the reference you’re making?

The label appears but you are still able to submit the device from a mobile device running the Android application? That’s very strange behavior.

In the form submit history on HQ does your cannot_continue_form question appear in the XML, and does it have a value?

@Clayton_Sims, @Mazz,

Yes i struggled with this a lot but then i deleted all three questions from the app and then re-added them and it seems to work on the mobile now but doesn’t work while using the android emulator app.

Glad to hear you were able to resolve it, and sorry to hear that it was challenging to resolve.

As I mentioned a bit above, unfortunately the app allowing you to proceed with this design this is a current limitation of the Web App entry system which doesn’t quite match the behavior of the mobile app, so not working in the Live Preview pane is expected behavior and doesn’t indicate anything wrong with your application or form.

-Clayton

Thank you, I am learning more and more not to rely on the web app for robust testing as it seems to have quite some limitations.