Skip to content

Commit

Permalink
Fixed issue #11516: Sliders (Multiple numerical input). It's possible…
Browse files Browse the repository at this point in the history
… continue without answering to mandatory question
  • Loading branch information
markusfluer committed Aug 4, 2016
1 parent ce60f6d commit 9bd89f3
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 52 deletions.
42 changes: 26 additions & 16 deletions application/helpers/qanda_helper.php
Expand Up @@ -2930,7 +2930,7 @@ function do_multiplenumeric($ia)
$slider_mintext = '';
$slider_max = '';
$slider_maxtext = '';
$slider_default = '';
$slider_default = null;
$slider_orientation= '';
$slider_handle = '';
$slider_custom_handle = '';
Expand Down Expand Up @@ -3031,25 +3031,35 @@ function do_multiplenumeric($ia)
// See : https://github.com/LimeSurvey/LimeSurvey/blob/master/scripts/bootstrap-slider.js#l1453-l1461
// If the bootstrapSlider were updated, most of this javascript would not be necessary.

$sValue = $slider_min;
$slider_user_no_action =1;

// value stored in _SESSION
if (isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname]))
{
$sValue = $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname];
$slider_user_no_action = 0;
}
elseif( $slider_default != "" )
$sValue = null;

if(App()->request->getPost('slider_user_no_action_'.$myfname))
{
$sValue = $slider_default;
$slider_user_no_action = 0;
}
elseif( isset($slider_middlestart) && $slider_middlestart!='')
$slider_user_no_action = App()->request->getPost('slider_user_no_action_'.$myfname);
}
else
{
$sValue = $slider_middlestart;
$slider_user_no_action = 1;

// value stored in _SESSION
if (isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname]))
{
$sValue = $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname];
$slider_user_no_action = 0;
}
elseif( $slider_default != "" )
{
$sValue = $slider_default;
$slider_user_no_action = 0;
}
elseif( isset($slider_middlestart) && $slider_middlestart!='')
{
$sValue = $slider_middlestart;
}

}


$sUnformatedValue = $sValue;

if(strpos($sValue,"."))
Expand Down
Expand Up @@ -61,10 +61,10 @@ class="text form-control pull-left <?php echo $kpclass;?>"
type="text"
name="<?php echo $myfname;?>"
id="answer<?php echo $myfname; ?>"
value="<?php echo $dispVal;?>"
value="<?php echo ($dispVal ? $dispVal : null); ?>"
onkeyup="<?php echo $checkconditionFunction; ?>"
<?php echo $maxlength; ?>
data-slider-value="<?php echo $sUnformatedValue;?>"
data-slider-value="<?php echo ($dispVal ? $dispVal : null); ?>"
data-slider-min='<?php echo $slider_min;?>'
data-slider-max='<?php echo $slider_max;?>'
data-slider-step='<?php echo $slider_step;?>'
Expand Down Expand Up @@ -107,7 +107,7 @@ class="text form-control pull-left <?php echo $kpclass;?>"


</div>
<input type="hidden" name="slider_user_no_action_<?php echo $myfname; ?>" id="slider_user_no_action_<?php echo $myfname; ?>" value="<?php echo $slider_user_no_action?>" />
<input type="hidden" name="slider_user_no_action_<?php echo $myfname; ?>" id="slider_user_no_action_<?php echo $myfname; ?>" value="<?php echo ($dispVal ? 0 : 1);?>" />
</div> <!-- form group -->
</div>

Expand All @@ -131,7 +131,6 @@ class="text form-control pull-left <?php echo $kpclass;?>"
</style>
</div>
<script type='text/javascript'>
<!--
// Most of this javascript is here to handle the fact that bootstrapSlider need numerical value in the input
// It can't accept "NULL" nor anyother thousand separator than "." (else it become a string)
// See : https://github.com/LimeSurvey/LimeSurvey/blob/master/scripts/bootstrap-slider.js#l1453-l1461
Expand All @@ -144,12 +143,15 @@ class="text form-control pull-left <?php echo $kpclass;?>"
var $prefix = $inputEl.data('slider-prefix');
var $suffix = $inputEl.data('slider-suffix');
var $separator = $inputEl.data('separator');

// We start the slider, and provide it the formated value with prefix and suffix for its tooltip
// Use closure for namespace, so we can use theSlider variable for all sliders.
(function () {
var theSlider = $inputEl.bootstrapSlider({
value : <?php echo ($dispVal ? $dispVal : 'null'); ?>,
formatter: function (value) {
if($sliderNoActionEl.val()=="1"){
return null;
}
displayValue = value.toString().replace('.',$separator);
return $prefix + displayValue + $suffix;
},
Expand Down Expand Up @@ -177,7 +179,7 @@ class="text form-control pull-left <?php echo $kpclass;?>"
if($sliderNoActionEl.val()=="1")
{
$('#javatbd' + myfname).find('div.tooltip').hide();
$inputEl.attr('value', '');
$inputEl.attr('value', null);
}

// Click the reset button
Expand All @@ -188,13 +190,13 @@ class="text form-control pull-left <?php echo $kpclass;?>"
$sliderNoActionEl.val("1");

// Position slider button at beginning
theSlider.bootstrapSlider('setValue', parseFloat($inputEl.attr('data-slider-min')));
theSlider.bootstrapSlider('setValue', null);

// Set value to null
$inputEl.attr('value', '');
$inputEl.attr('value', null);

// Why the fuck not?
LEMrel<?php echo $qid; ?>() // We call the EM
// LEMrel<?php echo $qid; ?>() // We call the EM
});

// On form submission, if user action is still on,
Expand All @@ -212,14 +214,13 @@ class="text form-control pull-left <?php echo $kpclass;?>"

if($sliderNoActionEl.val()=="1")
{
$inputEl.val('');
$inputEl.val(null);
}
return true;
});
$("#vmsg_<?php echo $qid;?>_default").text('<?php eT('Please click and drag the slider handles to enter your answer.');?>');
})();
});
-->
</script>
<?php endif; ?>
<!-- end of answer_row -->
75 changes: 53 additions & 22 deletions third_party/bootstrap-slider/bootstrap-slider.js
@@ -1,9 +1,9 @@
/*! =======================================================
VERSION 7.0.1
VERSION 9.1.1
========================================================= */
"use strict";

function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };

/*! =========================================================
* bootstrap-slider.js
Expand Down Expand Up @@ -52,6 +52,21 @@ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.const
window.Slider = factory(window.jQuery);
}
})(function ($) {
// Constants
var NAMESPACE_MAIN = 'slider';
var NAMESPACE_ALTERNATE = 'bootstrapSlider';

// Polyfill console methods
if (!window.console) {
window.console = {};
}
if (!window.console.log) {
window.console.log = function () {};
}
if (!window.console.warn) {
window.console.warn = function () {};
}

// Reference to Slider constructor
var Slider;

Expand Down Expand Up @@ -294,7 +309,7 @@ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.const
/*************************************************
CONSTRUCTOR
**************************************************/
Slider = function (element, options) {
Slider = function Slider(element, options) {
createNewSlider.call(this, element, options);
return this;
};
Expand Down Expand Up @@ -433,20 +448,19 @@ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.const
/* Create ticks */
this.ticks = [];
if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
this.ticksContainer = document.createElement('div');
this.ticksContainer.className = 'slider-tick-container';

for (i = 0; i < this.options.ticks.length; i++) {
var tick = document.createElement('div');
tick.className = 'slider-tick';

this.ticks.push(tick);
sliderTrack.appendChild(tick);
this.ticksContainer.appendChild(tick);
}

sliderTrackSelection.className += " tick-slider-selection";
}

sliderTrack.appendChild(sliderMinHandle);
sliderTrack.appendChild(sliderMaxHandle);

this.tickLabels = [];
if (Array.isArray(this.options.ticks_labels) && this.options.ticks_labels.length > 0) {
this.tickLabelContainer = document.createElement('div');
Expand Down Expand Up @@ -500,6 +514,12 @@ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.const
if (this.tickLabelContainer) {
this.sliderElem.appendChild(this.tickLabelContainer);
}
if (this.ticksContainer) {
this.sliderElem.appendChild(this.ticksContainer);
}

this.sliderElem.appendChild(sliderMinHandle);
this.sliderElem.appendChild(sliderMaxHandle);

/* Append slider element to parent container, right before the original <input> element */
parent.insertBefore(this.sliderElem, this.element);
Expand Down Expand Up @@ -710,7 +730,7 @@ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.const
step: 1,
precision: 0,
orientation: 'horizontal',
value: 5,
value: null,
range: false,
selection: 'before',
tooltip: 'show',
Expand Down Expand Up @@ -750,7 +770,7 @@ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.const

setValue: function setValue(val, triggerSlideEvent, triggerChangeEvent) {
if (!val) {
val = 0;
val = null;
}
var oldValue = this.getValue();
this._state.value = this._validateInputValue(val);
Expand Down Expand Up @@ -1177,6 +1197,7 @@ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.const
var diff1 = Math.abs(this._state.percentage[0] - percentage);
var diff2 = Math.abs(this._state.percentage[1] - percentage);
this._state.dragged = diff1 < diff2 ? 0 : 1;
this._adjustPercentageForRangeSliders(percentage);
} else {
this._state.dragged = 0;
}
Expand Down Expand Up @@ -1574,20 +1595,20 @@ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.const
if (this.options.orientation === 'vertical') {
var tooltipPos = this.options.tooltip_position || 'right';
var oppositeSide = tooltipPos === 'left' ? 'right' : 'left';
tooltips.forEach((function (tooltip) {
tooltips.forEach(function (tooltip) {
this._addClass(tooltip, tooltipPos);
tooltip.style[oppositeSide] = '100%';
}).bind(this));
}.bind(this));
} else if (this.options.tooltip_position === 'bottom') {
tooltips.forEach((function (tooltip) {
tooltips.forEach(function (tooltip) {
this._addClass(tooltip, 'bottom');
tooltip.style.top = 22 + 'px';
}).bind(this));
}.bind(this));
} else {
tooltips.forEach((function (tooltip) {
tooltips.forEach(function (tooltip) {
this._addClass(tooltip, 'top');
tooltip.style.top = -this.tooltip.outerHeight - 14 + 'px';
}).bind(this));
}.bind(this));
}
}
};
Expand All @@ -1596,13 +1617,23 @@ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.const
Attach to global namespace
*********************************/
if ($) {
var namespace = $.fn.slider ? 'bootstrapSlider' : 'slider';
$.bridget(namespace, Slider);
(function () {
var autoRegisterNamespace = void 0;

if (!$.fn.slider) {
$.bridget(NAMESPACE_MAIN, Slider);
autoRegisterNamespace = NAMESPACE_MAIN;
} else {
window.console.warn("bootstrap-slider.js - WARNING: $.fn.slider namespace is already bound. Use the $.fn.bootstrapSlider namespace instead.");
autoRegisterNamespace = NAMESPACE_ALTERNATE;
}
$.bridget(NAMESPACE_ALTERNATE, Slider);

// Auto-Register data-provide="slider" Elements
$(function () {
$("input[data-provide=slider]")[namespace]();
});
// Auto-Register data-provide="slider" Elements
$(function () {
$("input[data-provide=slider]")[autoRegisterNamespace]();
});
})();
}
})($);

Expand Down
6 changes: 3 additions & 3 deletions third_party/bootstrap-slider/bootstrap-slider.min.js

Large diffs are not rendered by default.

1 comment on commit 9bd89f3

@LouisGac
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, after a clarification:

In this commit there is the update to v9 and the hack you did on it.
If the hack is very small: could be ok. But please, separate the update and the hack in 2 commits so we have a trace of it.

Please sign in to comment.