Connonymous Posted November 26, 2023 Report Share Posted November 26, 2023 As far as I understand, you cannot use both and AND or logic in the rules portion of a datapage to make a field required, however that is what I am trying to do. I am fairly new to JavaScript, and also don't completely understand all the particularities of how Caspio references different elements. I have written out the following script in an attempt to make a field required based on certain criteria, but this does not seem to work as expected. Any help would be appreciated! To give more background on the app and the overall goal, this is a performance evaluation application, and the attempt is to require a comment if a certain evaluation score is selected. For example, the organization can declare that any score of 1 must require a comment to go along explaining why a score of 1 was given, etc. <script> let Q1C = document.querySelector('[id*=cbd_JPT_Performance_Eval_Q1_Scr#]'); if ((Q1C.value == '1' && '[@field:a_JPT_Organizations_Comment1_Req^]' == 'TRUE') || (Q1C.value == '2' && '[@field:a_JPT_Organizations_Comment2_Req^]' == 'TRUE') || (Q1C.value == '3' && '[@field:a_JPT_Organizations_Comment3_Req^]' == 'TRUE') || (Q1C.value == '4' && '[@field:a_JPT_Organizations_Comment4_Req^]' == 'TRUE') || (Q1C.value == '5' && '[@field:a_JPT_Organizations_Comment5_Req^]' == 'TRUE')) { document.getElementById("EditRecordd_JPT_Performance_Eval_Q1_Comment").required = true; } </script> Quote Link to comment Share on other sites More sharing options...
CoopperBackpack Posted November 27, 2023 Report Share Posted November 27, 2023 Hello @Connonymous, It looks like you can do this without JavaScript but by using the Calculated Value. 1) Add a Virtual field that is set to the Calculated Value, and add the formula: CASE WHEN ([@field:cbd_JPT_Performance_Eval_Q1_Scr] = 1 AND [@field:a_JPT_Organizations_Comment1_Req] = 1) OR ([@field:cbd_JPT_Performance_Eval_Q1_Scr] = 2 AND [@field:a_JPT_Organizations_Comment2_Req] = 1) OR ([@field:cbd_JPT_Performance_Eval_Q1_Scr] = 3 AND [@field:a_JPT_Organizations_Comment3_Req] = 1) OR ([@field:cbd_JPT_Performance_Eval_Q1_Scr] = 4 AND [@field:a_JPT_Organizations_Comment4_Req] = 1) OR ([@field:cbd_JPT_Performance_Eval_Q1_Scr] = 5 AND [@field:a_JPT_Organizations_Comment5_Req] = 1) THEN 1 ELSE 0 END Double-check the formula logic (field names and values). The idea is to return '1' if the condition is met and '0' if the condition is not met. You may use different values, it doesn`t matter. This value should be used in the Rule. 2) Create a Rule like "If Virtual field = 1 (in this example), make the field required" Quote Link to comment Share on other sites More sharing options...
Connonymous Posted November 27, 2023 Author Report Share Posted November 27, 2023 @CoopperBackpack Ah, thank you, that's a good idea! It seems to be working as expected. Slight delay after clicking one of the options that is not present when only checking the criteria through standard (non-virtual) fields though. Is there any way around this, or is checking the multiple criteria likely just going to lead to some delay? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.