ryansuitposungkono / openjs-grid

Automatically exported from code.google.com/p/openjs-grid
0 stars 0 forks source link

Input gets cut off after single quote #18

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Enter something like: hell'o world (with a single quote after hell)
2. Save
3. Grid will show hell instead hell'o world

What is the expected output?
hell'o world (it comes back in the ajax!!!)
What do you see instead?
hell

What version of the product are you using? On what operating system?
FF 4 on a mac

Please provide any additional information below.
Can I contribute any fixes?

Original issue reported on code.google.com by mcl...@spaceweb.nl on 7 Jun 2011 at 10:39

GoogleCodeExporter commented 9 years ago
I found the issue in line 831.
The quoting is completely wrong there. Therefore browsers will try to interpret 
the input themselves.

Here is the corrected line:
var $input = $('<input '+maxlength+' class="editableInput '+xtraClass+'" 
type="text" value="' + $td.text() + '"/>');

You have to swap double for single quotes and vice versa. Attributes are to be 
double quoted in html mind you!

Original comment by mcl...@spaceweb.nl on 7 Jun 2011 at 12:12

GoogleCodeExporter commented 9 years ago
This makes it so you can have double quotes either. I'm going to leave it the 
way I had it and just escape both possibilities.

so 

var text = $td.text().replace(/"/g,"\"").replace(/'/g,"\'");
and use text instead of $td.text();

Original comment by Seancla...@gmail.com on 5 Jul 2011 at 4:53

GoogleCodeExporter commented 9 years ago
you know what. That doesn't fix it. I see why you did that. It still holds a 
double quote problem.
Using yours and this replaces fixes it.

var text = $td.text().replace(/"/g,""");
var $input = $('<input '+maxlength+' class="editableInput '+xtraClass+'" 
type="text" value="' + text + '"/>');

Original comment by Seancla...@gmail.com on 5 Jul 2011 at 5:03

GoogleCodeExporter commented 9 years ago

Original comment by Seancla...@gmail.com on 5 Jul 2011 at 5:06

GoogleCodeExporter commented 9 years ago
In fact, I found a much better way to solve this issue, that arises because of 
the double quotes, but I rejected that after I discovered the single quotes, 
that are just invalid. I thought I had solved it after rejecting the single 
quotes, but realized only later I was wrong because of double quotes.

What you can do is much simpler. Do not put the value in when you create 
$input. Create $input without the value, and after that, do $($input)val(val); 
Where val is a variable that holds the value. That way, you have no problem 
with any content, because jQuery will handle all possible escaping scenarios 
for you.

Original comment by mcl...@spaceweb.nl on 5 Jul 2011 at 7:39

GoogleCodeExporter commented 9 years ago
haha wow. I kind of feel like an idiot for not seeing that.

var $input = $('<input '+maxlength+' class="editableInput '+xtraClass+'" 
type="text" />');
$input.val($td.text());

Original comment by Seancla...@gmail.com on 5 Jul 2011 at 3:35

GoogleCodeExporter commented 9 years ago

Original comment by Seancla...@gmail.com on 20 Jul 2011 at 3:15