Checkbox Validation - Number of response options

Hi there!

I'm trying to implement a validation on a checkbox field but I can't figure out to do it in OpenClinica. I have a 10 options checkbox field and the user will be allowed to have only 3 options checked. If more than 3 options are checked, I want a query to be triggered to the user. Does anyone here may help on this issue?

Kindest regards,
David

Comments

  • haenselhaensel Posts: 530 ✭✭
    Hi David

    There is no feature in OC that supports this check by default. You may try to use Javascript for it but this isn't trivial.

    Regards,
    Christian

    12.2.2 The calculation Script
  • GerbenRienkGerbenRienk Posts: 712 ✭✭✭
    Hi David,
    Here's a variation on http://www.trialdatasolutions.com/tds/howto/warning.jsp

    <div id="CheckBoxCount"> </div>
    <script src="includes/jmesa/jquery.min.js"></script>
    <script>
    $.noConflict();
    jQuery(document).ready(function($) {
    // make an array of the check boxes
    var checkboxesToCount = $("#CheckBoxCount").parent().parent().find("input");
    // and make a variable to count how many boxes are checked
    var checkedBoxes;
    function setMessageCheckBoxes(){
      checkedBoxes = 0;
      //loop through the array
        for (var i = 0; i < checkboxesToCount.length; i++) {
          if (checkboxesToCount[i].checked) {
          checkedBoxes = checkedBoxes + 1;
           }
        }
      // now evaulate what you found
      if (checkedBoxes > 3){
        $("#CheckBoxCount").html("Please choose 3 animals at most");
        }
      else {
        $("#CheckBoxCount").html("");
      };
    };
    checkboxesToCount.change(function(){
      setMessageCheckBoxes();
    });
    setMessageCheckBoxes();
    })
    </script>
  • davidmanteigasdavidmanteigas Posts: 14
    Hi Haensel and GerbenRiek,

    Thank you for you answers.

    GerbenRiek, your solution triggers a text, but what I meant was a validation to trigger a query when the CRF is saved with more than 3 checkbox's selected.

    Regards,
    David
  • haenselhaensel Posts: 530 ✭✭
    Hi David

    So you do not want the user to be warned when he saves the crf and give him the option to change the selected values? You want the crf to be saved without any notification and to create a discrepancy note (query) for the user automatically?

    Regards,
    Christian
  • davidmanteigasdavidmanteigas Posts: 14
    Hi Christian,

    Yes, I want the eCRF to trigger a discrepancy note for the user, not a warning.

    Regards,
    David
  • haenselhaensel Posts: 530 ✭✭
    edited March 16
    Hi David

    This is possible using rules. You can use the action type DiscrepancyNoteAction. It will be a lot work to create the expression because you have to check for all combinations but it is possible.

    e.g.

    (I_CHKBX ct "value1" AND I_CHKBX ct "value2" AND I_CHKBX ct "value3" AND I_CHKBX ct "value4") OR
    (I_CHKBX ct "value1" AND I_CHKBX ct "value2" AND I_CHKBX ct "value3" AND I_CHKBX ct "value5") OR
    (I_CHKBX ct "value1" AND I_CHKBX ct "value2" AND I_CHKBX ct "value3" AND I_CHKBX ct "value6") OR
    (I_CHKBX ct "value1" AND I_CHKBX ct "value2" AND I_CHKBX ct "value3" AND I_CHKBX ct "value7") OR
    ...
    6.4.4 (Rule) Action Types

    Regards,
    Christian
  • haenselhaensel Posts: 530 ✭✭
    edited March 16
    For ten checkboxes it is

    n = 10
    k = 4

    (n!)/((n-k)!*k!)

    => 210 combinations


    Regards,
    Christian

    Wikipedia: Combination
  • davidmanteigasdavidmanteigas Posts: 14
    edited March 16
    Hi Christian,

    That is what I have tought. It is almost impossible to implement.
    Future releases of OpenClinica should consider this feature, since it is a really common validation for checkbox's.

    Regards,
    David
  • GerbenRienkGerbenRienk Posts: 712 ✭✭✭
    Hi David,
    As an alternative you could add a few lines to the javascript and write the number of boxes checked to another CRF-item and then create a validation on that item.
    Gerben Rienk
  • ccollinsccollins Posts: 361 admin
    via Email
    This type of validation will be supported in OpenClinica 4, e.g.

    count-selected(.)<=4

    meaning you can't select more than 4 choices or there will be an error.


    Best,
    Cal
Sign In or Register to comment.