diff --git a/application/helpers/expressions/em_manager_helper.php b/application/helpers/expressions/em_manager_helper.php index 2614df8079e..b4c62298789 100644 --- a/application/helpers/expressions/em_manager_helper.php +++ b/application/helpers/expressions/em_manager_helper.php @@ -1445,9 +1445,11 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL) if ($hasSubqs) { $subqs = $qinfo['subqs']; $sq_names=array(); + $sq_eqPart=array(); foreach($subqs as $subq) { $sq_names[] = $subq['varName'].".NAOK"; + $sq_eqPart[] = "!is_empty({$subq['varName']})*{$subq['csuffix']}"; } if (!isset($validationEqn[$questionNum])) { @@ -1457,7 +1459,7 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL) 'qtype' => $type, 'type' => 'default', 'class' => 'default', - 'eqn' => 'unique(' . implode(',',$sq_names) . ')', + 'eqn' => 'unique(' . implode(',',$sq_names) . ') and count(' . implode(',',$sq_names) . ')==max('. implode(',',$sq_eqPart) .')', 'qid' => $questionNum, ); } @@ -3087,7 +3089,7 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL) $qtips['default']=$this->gT("Only numbers may be entered in these fields."); break; case 'R': - $qtips['default']=$this->gT("All your answers must be different."); + $qtips['default']=$this->gT("All your answers must be different and you must rank in order."); break; // Helptext is added in qanda_help.php /* case 'D': @@ -7196,6 +7198,14 @@ static function GetRelevanceAndTailoringJavaScript() $relParts[] = " $('#answer" . $sq['sgqa'] . "NANS').attr('checked',true);\n"; $relParts[] = " }\n"; break; + case 'R': + $listItem = substr($sq['rowdivid'],strlen($sq['sgqa'])); + $relParts[] = " $('#question{$arg['qid']} .select-list select').each(function(){ \n"; + $relParts[] = " if($(this).val()=='{$listItem}'){ \n"; + $relParts[] = " $(this).val('').trigger('change'); \n"; + $relParts[] = " }; \n"; + $relParts[] = " }); \n"; + break; default: break; } diff --git a/scripts/expressions/em_javascript.js b/scripts/expressions/em_javascript.js index 11326b27de5..af2f52805cd 100644 --- a/scripts/expressions/em_javascript.js +++ b/scripts/expressions/em_javascript.js @@ -20,7 +20,7 @@ /* Default event to trigger on answer part * see https://manual.limesurvey.org/Project_ideas_for_GSoC_2015#Expression_Manager_JavaScript_optimizations - * Actually only for list with comment + * Actually only for list with comment and select in ranking **/ $(document).on("keyup",".text-item textarea:not([onkeyup]),.text-item :text:not([onkeyup])",function(event){ // 'keyup' can be replaced by event.type (but not really needed) @@ -34,6 +34,11 @@ $(document).on("keyup",".text-item textarea:not([onkeyup]),.text-item :text:not( checkconditions($(this).val(), $(this).attr('name'), 'text', 'keyup') } }); +$(document).on("change",".select-item select:not([onchange])",function(event){ + //$('#java'+$(this).attr("name")).val($(this).val()); Not needed for ranking, needed for ? select already have val() and are unique by name + if($.isFunction(window.ExprMgr_process_relevance_and_tailoring )) + ExprMgr_process_relevance_and_tailoring("onchange",$(this).attr("name"),"select-one"); +}); function LEMcount() { diff --git a/scripts/ranking.js b/scripts/ranking.js index f57fb4ad0d1..f6db746f0d8 100644 --- a/scripts/ranking.js +++ b/scripts/ranking.js @@ -1,3 +1,14 @@ +/* + * This file is part of LimeSurvey + * See COPYRIGHT.php for copyright notices and details. + * @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GNU/GPL License v2 or later + */ + +/** + * Update answers part for ranking function + * + * @param {number} qId The qid of the question where apply. + */ function doDragDropRank(qID, showpopups, samechoiceheight, samelistheight) { // TODO : advanced setting in attributes if (typeof showpopups === 'undefined'){showpopups=true;} @@ -8,16 +19,19 @@ function doDragDropRank(qID, showpopups, samechoiceheight, samelistheight) { var rankingnamewidth=rankingname.length; //Add a class to the question $('#question'+qID+'').addClass('dragDropRanking'); - // Hide the default answers list - // Display for media oral, maybe use !window.matchMedia("(oral)").matches but still hidden if user use default browser with screen reader ? + // Hide the default answers list but display for media oral or screen reader $('#question'+qID+' .answers-list').addClass("hide"); // We are in javascript, then default tip can be replaced - $('#question'+qID+' .em_default').html(aRankingTranslations.rankhelp); - + $('#question'+qID+' .em_default').html("
"+$('#question'+qID+' .em_default').html()+"
"); + $('#question'+qID+' .answers-list').on("change",".select-item",{source:false},function(event,data){ + data = data || event.data; + if(data.source!='dragdrop') + loadDragDropRank(qID);; + }); // Add connected sortables elements to the question // Actually a table : move it to a list is a good idea, but need reviewing template a lot. - var htmlCode = '
\ + var htmlCode = '