Commit 5901b9ea authored by Chenu Denis's avatar Chenu Denis

Dev: New feature #8247: allow deactivate Javascript autocorrection of numerical values

Dev: Added LSvar object in template, maybe elsewhere is better, but already have needed script
Dev: add setJsVar for LEMradix, numRegex and intRegex
Dev: Start issue #8260: Can not use own script on question text : find another way ?
parent 0de1d2ad
......@@ -612,5 +612,11 @@ $config['styledir'] = $config['rootdir'].DIRECTORY_SEPARATOR.'sty
// Use alias notation, we should move to this format everywhere.
$config['plugindir'] = 'webroot.plugins';
// (javascript) Fix automatically the value entered in numeric question type : 1: remove all non numeric caracters; 0 : leave all caracters
$config['bFixNumAuto'] = 1;
// (javascript) Send real value entered when using Numeric question type in Expression Manager : 0 : {NUMERIC} with bad caracters send '', 1 : {NUMERIC} send all caracters entered
$config['bNumRealValue'] = 0;
return $config;
//settings deleted
......@@ -977,11 +977,11 @@ class SurveyRuntimeHelper {
// in order to workaround an not-reproduced issue #4453 (lemeur)
echo "<input type='text' id='runonce' value='0' style='display: none;'/>";
// lemradix and var for LemRadix
$sLemRadixVarScript=" LEMradix='" . $radix . "';\n"
." numRegex = new RegExp('[^-' + LEMradix + '0-9]','g');\n"
." intRegex = new RegExp('[^-0-9]','g');\n";
Yii::app()->clientScript->registerScript('LemRadixVarScript',$sLemRadixVarScript,CClientScript::POS_HEAD);
# // lemradix and var for LemRadix
# $sLemRadixVarScript=" LEMradix='" . $radix . "';\n"
# ." numRegex = new RegExp('[^-' + LEMradix + '0-9]','g');\n"
# ." intRegex = new RegExp('[^-0-9]','g');\n";
# Yii::app()->clientScript->registerScript('LemRadixVarScript',$sLemRadixVarScript,CClientScript::POS_HEAD);
$showpopups=Yii::app()->getConfig('showpopups');
//Display the "mandatory" message on page if necessary
......
......@@ -2425,10 +2425,6 @@
}else{
$sq_equs[] = '( is_numeric('.$sq_name.') || is_empty('.$sq_name.') )';
}
if($type=="K")
$subqValidSelector = $sq['jsVarName_on'];
else
$subqValidSelector = "";
}
if (!isset($validationEqn[$questionNum]))
{
......
......@@ -155,11 +155,27 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
}
if(stripos ($line,"{TEMPLATEJS}"))
{
// Javascript Var
$aLSJavascriptVar=array();
$aLSJavascriptVar['bFixNumAuto']=(int)(bool)Yii::app()->getConfig('bFixNumAuto',1);
$aLSJavascriptVar['bNumRealValue']=(int)(bool)Yii::app()->getConfig('bNumRealValue',0);
if(isset($thissurvey['surveyls_numberformat']))
{
$radix=getRadixPointData($thissurvey['surveyls_numberformat']);
}
else
{
$aLangData=getLanguageData();
$radix=getRadixPointData($aLangData[ Yii::app()->getConfig('defaultlang')]['radixpoint']);// or $clang->langcode . defaultlang ensure it's same for each language ?
}
$aLSJavascriptVar['sLEMradix']=$radix['separator'];
$sLSJavascriptVar="LSvar=".json_encode($aLSJavascriptVar);
App()->clientScript->registerScript('sLSJavascriptVar',$sLSJavascriptVar,CClientScript::POS_HEAD);
App()->clientScript->registerScript('setJsVar',"setJsVar();",CClientScript::POS_BEGIN);// Ensure all js var is set before rendering the page (User can click before $.ready)
App()->getClientScript()->registerPackage('jqueryui');
App()->getClientScript()->registerPackage('jquery-touch-punch');
App()->getClientScript()->registerPackage('jquery-touch-punch');
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."survey_runtime.js");
App()->getClientScript()->registerScriptFile($templateurl . 'template.js',CClientScript::POS_END);
App()->getClientScript()->registerScriptFile($templateurl . 'template.js',CClientScript::POS_BEGIN);
useFirebug();
}
......
......@@ -71,6 +71,23 @@ $(document).ready(function()
});
/**
* setJsVar : Get all global used var
*/
function setJsVar(){
if (typeof LSvar!="undefined" && LSvar instanceof Object == false) {
bFixNumAuto=1;
bNumRealValue=0;
LEMradix=".";
}
else {
bFixNumAuto=LSvar.bFixNumAuto;
bNumRealValue=LSvar.bNumRealValue;
LEMradix=LSvar.LEMradix;
}
numRegex = new RegExp('[^-' + LEMradix + '0-9]','g');
intRegex = new RegExp('[^-0-9]','g');
}
// Deactivate all other button on submit
function limesurveySubmitHandler(){
$(document).on("click",".disabled",function(){return false;});
......@@ -144,25 +161,25 @@ function checkconditions(value, name, type, evt_type)
*/
function fixnum_checkconditions(value, name, type, evt_type, intonly)
{
if(typeof bFixNumAuto == 'undefined'){bFixNumAuto=true;} // Allow deactivate fixnum in template or in Plugin
if(typeof bNumRealValue == 'undefined'){bNumRealValue=false;} // Allow to update {QCODE} even with text
newval = new String(value);
if (typeof intonly !=='undefined' && intonly==1) {
newval = newval.replace(intRegex,'');
}
else {
newval = newval.replace(numRegex,'');
}
aNewval = newval.split(LEMradix);
if(aNewval.length>0){
newval=aNewval[0];
}
if(aNewval.length>1){
newval=newval+"."+aNewval[1];
}
if (newval != '-' && newval != '.' && newval != '-.' && newval != parseFloat(newval)) {// Todo : do it in reg
newval = '';
if(!bNumRealValue)
{
if (typeof intonly !=='undefined' && intonly==1) {
newval = newval.replace(intRegex,'');
}
else {
newval = newval.replace(numRegex,'');
}
aNewval = newval.split(LEMradix);
if(aNewval.length>0){
newval=aNewval[0];
}
if(aNewval.length>1){
newval=newval+"."+aNewval[1];
}
if (newval != '-' && newval != '.' && newval != '-.' && newval != parseFloat(newval)) {// Todo : do it in reg
newval = '';
}
}
if(bFixNumAuto)
{
......@@ -179,14 +196,7 @@ function fixnum_checkconditions(value, name, type, evt_type, intonly)
{
evt_type = 'onchange';
}
if(bNumRealValue)
{
checkconditions(value, name, type, evt_type);
}
else
{
checkconditions(newval, name, type, evt_type);
}
checkconditions(newval, name, type, evt_type);
}
// Set jquery-ui to LS Button
......
......@@ -10,18 +10,18 @@
{TEMPLATEJS}
{GOOGLE_ANALYTICS_JAVASCRIPT}
</head>
<!--[if lt IE 7 ]> <body class="lang-{SURVEYLANGUAGE} {SURVEYFORMAT} ie ie6 ielt7 ielt8 ielt9 no-js"> <![endif]-->
<!--[if IE 7 ]> <body class="lang-{SURVEYLANGUAGE} {SURVEYFORMAT} ie ie7 ielt8 ielt9 no-js"> <![endif]-->
<!--[if IE 8 ]> <body class="lang-{SURVEYLANGUAGE} {SURVEYFORMAT} ie ie8ielt9 no-js"> <![endif]-->
<!--[if IE 9 ]> <body class="lang-{SURVEYLANGUAGE} {SURVEYFORMAT} ie ie9 no-js"> <![endif]-->
<!--[if gt IE 9]><!--><body id="body" class="lang-{SURVEYLANGUAGE} {SURVEYFORMAT} no-js"><!--<![endif]-->
<script type='text/javascript'>/*<![CDATA[*/(function(H){ H.className=H.className.replace(/\bno-js\b/,'js') })(document.getElementsByTagName('body')[0]);/*]]>*/</script>
<div id="container">
<body>
<!--[if lt IE 7 ]> <div id="container" class="lang-{SURVEYLANGUAGE} {SURVEYFORMAT} ie ie6 ielt7 ielt8 ielt9 no-js"> <![endif]-->
<!--[if IE 7 ]> <div id="container" class="lang-{SURVEYLANGUAGE} {SURVEYFORMAT} ie ie7 ielt8 ielt9 no-js"> <![endif]-->
<!--[if IE 8 ]> <div id="container" class="lang-{SURVEYLANGUAGE} {SURVEYFORMAT} ie ie8ielt9 no-js"> <![endif]-->
<!--[if IE 9 ]> <div id="container" class="lang-{SURVEYLANGUAGE} {SURVEYFORMAT} ie ie9 no-js"> <![endif]-->
<!--[if gt IE 9]><!--><div id="container" class="lang-{SURVEYLANGUAGE} {SURVEYFORMAT} no-js"><!--<![endif]-->
<script type='text/javascript'>/*<![CDATA[*/(function(H){ H.className=H.className.replace(/\bno-js\b/,'js') })(document.getElementById('container'));/*]]>*/</script>
<div id="head">
<div class="wrapper">
<!--<a href="#" title="Made with LimeSurvey" id="link-logo"><img src="{TEMPLATEURL}logo.png" alt=" " id="logo"/></a>-->
<div class="tools">{LANGUAGECHANGER}</div><h1 id="sitename">{SITENAME}</h1>
</div>
</div>
<div id="title"><h2 id="surveytitle" class="wrapper">{SURVEYNAME}</h2></div>
<div id="title"><h2 id="surveytitle" class="wrapper">{SURVEYNAME}</h2></div>
<div id="content" class="outerframe">
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment