Skip to content

Commit

Permalink
Dev: New feature #8247: allow deactivate Javascript autocorrection of…
Browse files Browse the repository at this point in the history
… 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 ?
  • Loading branch information
Shnoulle committed Oct 22, 2013
1 parent 0de1d2a commit 5901b9e
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 46 deletions.
6 changes: 6 additions & 0 deletions application/config/config-defaults.php
Expand Up @@ -612,5 +612,11 @@
// 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
10 changes: 5 additions & 5 deletions application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -977,11 +977,11 @@ function run($surveyid,$args) {
// 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
Expand Down
4 changes: 0 additions & 4 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -2425,10 +2425,6 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
}else{
$sq_equs[] = '( is_numeric('.$sq_name.') || is_empty('.$sq_name.') )';
}
if($type=="K")
$subqValidSelector = $sq['jsVarName_on'];
else
$subqValidSelector = "";
}
if (!isset($validationEqn[$questionNum]))
{
Expand Down
22 changes: 19 additions & 3 deletions application/helpers/replacements_helper.php
Expand Up @@ -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();
}

Expand Down
62 changes: 36 additions & 26 deletions scripts/survey_runtime.js
Expand Up @@ -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;});
Expand Down Expand Up @@ -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)
{
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions templates/citronade/startpage.pstpl
Expand Up @@ -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">

0 comments on commit 5901b9e

Please sign in to comment.