Validation Conditions

calculations

#1

Hi Team,

We are trying to create a form with the help of validation conditions, Example: “Number of Floors”: user should enter the value between the 1 to 100. if user is trying to enter the value beyond the boundary then the message should popup. In kobo Tool box while validating the form its work fine. But we are developing the Hybrid Application, their this condition is failing. Could you Please help us!

Thank you!


#2

@keerthi, what do you mean by “Tool box while validating the form its work fine. But we are developing the Hybrid Application, their this condition is failing” tell us more about the hybrid application


#3

Hi,

Thank you for the response,

We have created & deployed a form on the kobotoolbox.org wherein we have used the constraint and constraint message configurations.
Example: A field “Number of Floors” of type number; Constraint is minimum value as 1 and maximum value as 99; Constraint message as “Please enter value between 1 and 99 only”

When we use the “Preview” feature of the form and validate the form post filling the forms on the kobotoolbox.org, we observe that Constraints are working correctly and “Constraint message” appears when applicable

On the parallel side, we are using the Enketo translator to build a web / hybrid application which does not show the Constraint Messages as popup. Though submitting the form points it back to the field which has incorrect data (data which is failing the constraint validation), the constraint message itself does not appear.

Can you please highlight which part / key area that is responsible to show the constraint messages.


#4

Ca you share a portal of your form like questions before and after the constraint


#5

Hi,

I have one more Question.

1… I have created a form In Excel and uploaded to Kobotoolbox.org, It was successfully upload without any errors message, If I’m trying to preview it , I’m unable to see preview. when I tried to download the “XML” I’m getting 504 error message
.
2. Form edit is working fine, but while previewing I’m getting the same problem.


#6

@keerthi Share the excel form that you created with me. I will correct it and resend back to you.


#7

Hi,

Thank you for your response,

We have created a form with the help of dynamic values meaning we are having a question called “YES/NO/N/A” which are radio button. if we select “NO” some data should populate in an0thor field called “SIGNIFICATE DETAILS”.

  1. if we select option “NO” from radio button “YES/NO/N/A” ,some text will populate in “SIGNIFICATE DETAILS” and with additional to it we can enter data.

  2. If we Select “YES” in “YES/NO/N/A” then it will show blank so that we can enter some desired text.

we have achieved with this formula :
" if (${YES_NO_N_A0004}=“no”, “The premises is only occupied by Sanctuary Group staff and residents.”, (if (${YES_NO_N_A0004}=“yes”, " ", “”))) ".

So, Now If I’m going to enter some data manually in “SIGNIFCANT DETAILS” and saving the form with option “Save as draft” ,then on viewing the same form we are not able to see the pervious data posted.

Could you please help us with some suggestion that would solve this problem( the data should not lose once we fill the form).


#8

test.xlsx (9.7 KB)
I have designed a sample that works well for me. I use ODK collect to test this and it should work well with Kobo collect also. Please ensure you do not have multiple forms downloaded and installed otherwise the Edit Saved Form will display error. You can use the Delete Saved Form to remove duplicate of the form


#9

Hi,

Thank you for the quick response and the sample however our scenario is different

Requirements:

  • Requirement 1) Our form requests User to fill 2 fields.
    First Field is a Radio button with Choices as Yes; No and N/A (say the field name is YES_NO_N_A0004)
    Second Field is a Free text box which User can edit and type what ever is required (say the field name is SIGNIFCANT_DETAILS)
  • Requirement 2) If User selects “No” from the first field, then we require the second field to be pre-populated with a defined response as “The premises is only occupied by residents”
  • Requirement 3) If User selects “Yes” from the first field, then we require the second field NOT to be pre-populated so the User can update his own comments (second field being a free text)
  • Requirement 4) User should be able to save the form as draft before Saving it

Approach

  • We have defined 2 fields as required (i.e. YES_NO_N_A0004 and SIGNIFCANT_DETAILS).
  • We downloaded the Forms .xls format
  • In the .xls format, For the second field we have used the calculate column and updated the below a formula
  • if (${YES_NO_N_A0004}=“no”, “The premises is only occupied by residents.”, (if (${YES_NO_N_A0004}=“yes”, " ", “”)))

The above approach has solved our Requirements 1,2 and 3 but NOT Requirement 4

Problem Statement
When Form is launched for the first ever time, the Second Field i.e. “SIGNIFICANT_DETAILS” is pre-populated or left empty based on the first field selection of Yes and No choices however following are the outcomes when form is saved as a draft and again opened for editing

Scenario 1: – Failed

  1. Form launched first time, User selects “Yes” in first field and supply data as “Test Data” in the second field
  2. User saves the form as Draft
  3. User again launches the form to edit (the saved draft version)
  4. First field is selected as “Yes” however the second field is showing blank. “Test Data” typed earlier has disappeared and not visible

Scenario 2: – Failed

  1. Form launched first time, User selects “No” in first field
  2. Second field is pre-populated with “The premises is only occupied by residents”
  3. User edits the pre-populated data at the end as “The premises is only occupied by residents only for a week
  4. User saves the form as Draft
  5. User again launches the form to edit (the saved draft version)
  6. First field is selected as “No” however the second field is only showing “The premises is only occupied by residents” Edited data ‘only for a week’ has disappeared

Summary
We believe the Calculate logic is overriding the data captured during the first occasion of the form being saved as Draft and hence the field 2 is only showing results of the Calculation and not the data captured by the user

Please suggest the right approach to meet this requirement. Please note we have tried the “once” before the Calculate formula on Second field however this
a) Did not work as expected
b) Even if it works, would not let user define the toggle between Yes or No options multiple times on the submission of the form for the first occasion itself

Many Thanks
Keerthi


#10

Basically, you cant use a calculation to populate a default. If a question contains a calculation, then that calculation will determine what ultimately gets saved (calculations are re-run constantly whenever you do anything, including saving and opening a form…)

What you can do instead is actually have three text input questions, each with their own appropriate default, but only show one depending on what the user selects: Yes, No, or NA. And if you use the same prompt label for each, you can trick the user to think its the same question! :wink: Then, you have a final calculation for whatever you want to save as the overall result, which will obtain its value from whichever of the 3 questions is relevant.

Try this sample form to see what I mean:

defaults.xls (5.5 KB)