AnsweredAssumed Answered

PHP API: Require answer to checkbox question generated by a valuelist

Question asked by carmean on Oct 26, 2017

We require Students check at least one of the courses from a long valuelist auto generated from the values of a field.  I modified fmview.php so it works-

  if ($encodedEachValue[0] !== $eachvalue[0] ){

  $req_checkbox = " class='validate(minselect(1))'";

  }else{

  $req_checkbox = "";

  }

 

  if ($type == "checkbox") {

  echo "<input type='$type' name='$fieldName" . "[]'" . "value='$encodedStoredValue' $req_checkbox $selected>$encodedEachValue";

  }else{

  echo "<input type='$type' name='$fieldName' value='$encodedStoredValue' $selected>$encodedEachValue";

  }

 

This generates the code for every question with a checkbox:

<input type='checkbox' name='21[]'value='BPK105'  class='validate(minselect(1))' >BPK105  <input type='checkbox' name='21[]'value='BPK110' >BPK110  <input type='checkbox' name='21[]'value='BPK140' >BPK140 etc..

 

It requires every question with valuelist generated checkboxes on the questionnaire to be completed and it may take more of the server resources than necessary.  It would be much nicer to make it so it was only required for specific checkbox questions.  I understand (Thanks to Luca Fagipoli on StackOverflow) we can do it with

<div class="checkbox-group required">{Checkbox question}...</div>

with this expression:

$('div.checkbox-group.required :checkbox:checked').length > 0

But I need time to get that working.  Any suggestions are welcome!

Outcomes