This project is read-only.
2
Vote

stringify error in chrome and some other browser

description

The line:
itemdata('init', JSON.parse(JSON.stringify(item.data()))); //cheap way to create a clone
Gives a "Failed to read the 'selectionDirection' property from 'HTMLInputElement': The input element's type ('hidden') does not support selection." error in chrome and some mobile browsers.
The problem arises when instantiating from code in like this:
var evaluationDiv = $('<div></div>');
    var evaluationinput = $('<input name="Evaluations[' + cnt + '].Score" type="hidden"  id="ev' + cnt + '"  value="' + score + '" />');
    var rdiv = $('<div id="rateDiv_' + cnt + '"></div>');
    rdiv.rateit({ max: 5, resetable: false, step: 1, backingfld: evaluationinput });
    evaluationDiv.append(evaluationinput);
    evaluationDiv.append(rdiv);
it is related to this:
http://stackoverflow.com/questions/23073216/why-cant-you-stringify-a-jquery-object

Replacing with:
itemdata('init', $(item.html()));
Seems to solve the problem in all browsers

comments

gidon wrote Apr 29, 2014 at 7:25 AM

I see your mistake.

The backingfld property in the options object should be a string (the selector to find the backingfield), and not the element itself.

The stringify function just is the first place that throws an exception because of this mistake, it is ok by itself (because it stringifies the data object of the element, and no actual element).


** Closed by gidon 04/28/2014 11:25PM

runeemche wrote Apr 29, 2014 at 9:12 AM

Well it is hardly a mistake, since it's not really documented what type backingfld should be :)

Parsing the selector of the backingfield, here "#ev"+cnt, was the first I did, and since it has not been added to the document yet it fails - so it makes sense to parse the object I just created - and it also works fine, except in Chrome etc.

If I want a function that returns a form element with a rateit element I can place somewhere, it is detached until returning. It is very common to create controls, elements etc. and then adding them after - and that doesn't work right now.

Great plugin by the way! :)

adamjimenez wrote Jul 15, 2014 at 11:19 AM

I agree with this. This used to work in an older version of rateit. It's convenient to attach after creating the element without the need for a selector.

gidon wrote Jul 15, 2014 at 6:40 PM

I understand the problem. I would like to fix it. But I am currently swamped at work.
If you want you can try fixing it and sending me a pull request. (I moved to git a whole ago)

adamjimenez wrote Jul 15, 2014 at 7:28 PM

Is this the right repo?:
https://github.com/dandv/meteor-jquery-rateit

As the version seems older? 1.0.20 vs 1.0.22

gidon wrote Jul 16, 2014 at 12:02 PM

Nope, the git repo is still hosted here at codeplex. Click on the tab SourceCode, and you'll find how to clone and fork, and send pull-requests.