View Issue Details

IDProjectCategoryView StatusLast Update
08546Bug reports[All Projects] Survey takingpublic2014-01-25 17:22
ReporterfinnnnsAssigned ToDenisChenu 
PrioritynormalSeveritytweak 
Status closedResolutionfixed 
Product Version2.05+ 
Target VersionFixed in Version2.05+ 
Summary08546: JavaScript Expression Manager rtrim numeric value (not PHP)
Description

This happens in the following context:
You want an entry field either to have a number or be empty. In a matrix context having mixed string and numeric input fields
So, there must a validation in the format (is_numeric(foo) OR is_empty(foo))
Now, validating a false value with e.g. "12h" the validation text triggers the validation tip. When trying to send a javascript alert appears, and upon clicking "OK" the validation tip keeps displayed.
Validating a false value with e.g. "12 " the validation text does not trigger a validation tip. When trying to send a javascript alert appears, and upon clicking "OK" the validation tip disappears.
See the Screenshot attached

Steps To Reproduce

Create a matrix question with at least a subquestion having at least two input fields
Set a question validation equation in the form of (is_numeric(q1_sq1_sq2.NAOK) OR is_empty(q1_sq1_sq2.NAOK))
↑ this affects the second field of the first subquestion.

Set a question validation tip to be displayed, the (negative) same condition having a message and none for the opposite
{if((!is_numeric(q1_sq1_sq2.NAOK) && !is_empty(q1_sq1_sq2.NAOK)),'Number of Hours needs to be numeric<br />','')}

Test the survey

TagsNo tags attached.
Complete LimeSurvey version number (& build)2.05 131219
I will donate to the project if issue is resolvedNo
BrowserFirefox
Database & DB-VersionmySQL 5.1.66 latest DB-Version
Server OS (if known)Debian GNU/Linux 6.0.7 (squeeze)
Webserver software & version (if known)Apache
PHP Version5.3.3-7+squeeze15

Activities

finnnns

finnnns

2014-01-16 15:48

reporter  

limesurvey_is_numeric.lss (23,609 bytes)
finnnns

finnnns

2014-01-16 15:49

reporter  

screen01.png (51,476 bytes)
screen01.png (51,476 bytes)
finnnns

finnnns

2014-01-16 15:49

reporter  

screen02.png (162,823 bytes)
finnnns

finnnns

2014-01-16 15:49

reporter  

screen03.png (48,805 bytes)
screen03.png (48,805 bytes)
finnnns

finnnns

2014-01-16 15:49

reporter  

screen04.png (166,698 bytes)
finnnns

finnnns

2014-01-16 15:49

reporter  

screen05.png (48,278 bytes)
screen05.png (48,278 bytes)
DenisChenu

DenisChenu

2014-01-16 18:34

developer   ~27921

Hi strange here, because i can not reproduce on my installation.(test link : http://limesurvey.sondages.pro/survey/index/sid/562757/newtest/Y)

Can you test with last version please (from today).

If not OK : please : can you put complete PHP info.

DenisChenu

DenisChenu

2014-01-16 18:35

developer   ~27922

With Release 2.05+ Build 140116 please :)

finnnns

finnnns

2014-01-17 08:08

reporter   ~27930

Last edited: 2014-01-17 08:09

View 2 revisions

Yes I could reproduce it in http://limesurvey.sondages.pro/survey/index/sid/562757/newtest/Y as well as in my own 2.05+ Build 140116.
It's somehow hard to explain what it is exactly and I might not have pointed out the "trailing space problem" enough. However, I've put together a "comic strip" style explanation of the phenomen (see file 08546.png).
Later in the day I happily send you my anonymized phpinfo.

finnnns

finnnns

2014-01-17 08:08

reporter  

08546.png (184,531 bytes)
DenisChenu

DenisChenu

2014-01-17 08:27

developer   ~27931

Last edited: 2014-01-17 08:30

View 2 revisions

Yes, you're right: better understanding now : with trailing space it's different.

And it's only trailing space ......

You can do this :
(is_numeric(trim(q1_sq1_sq2.NAOK)) OR is_empty(q1_sq1_sq2.NAOK))

PS: not a server difference, no need phpinfo ;)

DenisChenu

DenisChenu

2014-01-17 08:29

developer   ~27932

Reminder sent to: c_schmitz

Hi Carsten, don't know what to do here:

For js is_numeric("12 ") is true (not is_numeric(" 12").)
For php is_numeric("12 ") is false (same with is_numeric(" 12").)

Did we trim allways or not ?

finnnns

finnnns

2014-01-17 08:47

reporter   ~27933

Glad not having to send the phpinfo.
Regarding your note 27931: If that's the case - in my understanding - you're willed to have values with trailing spaces in your survey answer's data, aren't you?
The whole thing is a finesse, admittedly, but maybe worth to make LimeSurvey even more perfect.

DenisChenu

DenisChenu

2014-01-17 09:10

developer   ~27935

It's not finesse ;).

But here i really don't know what is best .....

is_numeric("12 ") false or true ? I thing false (like PHP) but not sure it's break another survey.

What is your opinion on this?

And when we export : for OOcalc "12 " become 12 or not ? And for spss ? And for other expression ....
I think we can have difference too if we do:
{q1_sq1_sq2.NAOK+q1_sq1_sq2.NAOK}
with or without trailing space .....

c_schmitz

c_schmitz

2014-01-17 09:14

administrator   ~27936

Last edited: 2014-01-17 09:14

View 2 revisions

I think the behaviour between PHP and JS should be the same.
PHP uses the us_numeric function.
I suggest to replace the function LEMis_numeric(a) by the PHPJS version here http://phpjs.org/functions/is_numeric/

That way the problem will be gone.

DenisChenu

DenisChenu

2014-01-17 09:14

developer   ~27937

{q1_sq1_sq2.NAOK+q1_sq1_sq2.NAOK}

In JS:
If you put " 12" : you have " 12 12"
If you put "12 " : you have 24

In PHP:
If you put " 12" : you have " 12 12"
If you put "12 " : you have "12 12 "

DenisChenu

DenisChenu

2014-01-17 09:45

developer   ~27941

I fix first LEMval to never rtrim value, see for is_numeric after.

Maybe phpjs can be extrenal for EM, but have a lot of function uneeded (actually).

DenisChenu

DenisChenu

2014-01-17 14:42

developer   ~27959

phpjs seems have same issue here:
PHP : is_numeric("12 ") is false
phpjs: is_numeric("12 ") is true

c_schmitz

c_schmitz

2014-01-17 15:13

administrator   ~27960

hehe, lets submit a bug report ;)

c_schmitz

c_schmitz

2014-01-17 15:14

administrator   ~27961

ha, I see you already did ;)

DenisChenu

DenisChenu

2014-01-17 16:31

developer   ~27965

Yes and make a pull request:
https://github.com/kvz/phpjs/pull/133

This work good on LS. Do the pull for LS and update with newer pĥpjs if needed (surely better).

DenisChenu

DenisChenu

2014-01-18 15:57

developer   ~27984

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&amp;id=13713

DenisChenu

DenisChenu

2014-01-18 15:59

developer   ~27985

Fix JS to have same way than PHP.
is_numeric(QQ) with QQ at " 3" is true.

Fix too is_int for all traing slash.
TODO : fix is_float (PHP broken actually)

c_schmitz

c_schmitz

2014-01-25 17:22

administrator   ~28161

2.05+ Build 140125 released

Related Changesets

LimeSurvey: master 5099401e

2014-01-18 14:57:06

DenisChenu

Details Diff
Fixed issue 08546: JavaScript Expression Manager rtrim numeric value (not PHP)
Dev: use phpjs function AND fix LEMval
Dev: fix is_int with phpjs too
Dev: PHP is_float return allways false for QCODE actually : TODO add exprmgr_int (same in 2.00)
mod - scripts/expressions/em_javascript.js Diff File

Issue History

Date Modified Username Field Change
2014-01-16 15:48 finnnns New Issue
2014-01-16 15:48 finnnns File Added: limesurvey_is_numeric.lss
2014-01-16 15:49 finnnns File Added: screen01.png
2014-01-16 15:49 finnnns File Added: screen02.png
2014-01-16 15:49 finnnns File Added: screen03.png
2014-01-16 15:49 finnnns File Added: screen04.png
2014-01-16 15:49 finnnns File Added: screen05.png
2014-01-16 16:19 c_schmitz Assigned To => DenisChenu
2014-01-16 16:19 c_schmitz Status new => assigned
2014-01-16 18:34 DenisChenu Note Added: 27921
2014-01-16 18:35 DenisChenu Note Added: 27922
2014-01-16 18:35 DenisChenu Status assigned => feedback
2014-01-17 08:08 finnnns Note Added: 27930
2014-01-17 08:08 finnnns Status feedback => assigned
2014-01-17 08:08 finnnns File Added: 08546.png
2014-01-17 08:09 finnnns Note Edited: 27930 View Revisions
2014-01-17 08:27 DenisChenu Note Added: 27931
2014-01-17 08:27 DenisChenu Summary is_numeric not behaving consistently between validation and validation help text, depending on erraneous value => JS and PHP difference between is_numeric : JS rtrim value, not PHP
2014-01-17 08:29 DenisChenu Note Added: 27932
2014-01-17 08:30 DenisChenu Note Edited: 27931 View Revisions
2014-01-17 08:47 finnnns Note Added: 27933
2014-01-17 09:10 DenisChenu Note Added: 27935
2014-01-17 09:14 c_schmitz Note Added: 27936
2014-01-17 09:14 DenisChenu Note Added: 27937
2014-01-17 09:14 c_schmitz Note Edited: 27936 View Revisions
2014-01-17 09:16 DenisChenu Summary JS and PHP difference between is_numeric : JS rtrim value, not PHP => JavaScript Expression Manager rtrim numeric value
2014-01-17 09:16 DenisChenu Summary JavaScript Expression Manager rtrim numeric value => JavaScript Expression Manager rtrim numeric value (not PHP)
2014-01-17 09:45 DenisChenu Note Added: 27941
2014-01-17 14:42 DenisChenu Note Added: 27959
2014-01-17 15:13 c_schmitz Note Added: 27960
2014-01-17 15:14 c_schmitz Note Added: 27961
2014-01-17 16:31 DenisChenu Note Added: 27965
2014-01-18 15:57 DenisChenu Changeset attached => LimeSurvey master 5099401e
2014-01-18 15:57 DenisChenu Note Added: 27984
2014-01-18 15:57 DenisChenu Resolution open => fixed
2014-01-18 15:59 DenisChenu Note Added: 27985
2014-01-18 15:59 DenisChenu Status assigned => resolved
2014-01-18 15:59 DenisChenu Fixed in Version => 2.05+
2014-01-25 17:22 c_schmitz Note Added: 28161
2014-01-25 17:22 c_schmitz Status resolved => closed