doElementFX clear is failing with Syntax Error

achartier

Administrator
Staff member
I am calling this function in element javascript to clear another elements value.

The clear function in element.js is calling the dropdown.js update function with an empty string. The argument is typeof string and for some reason JSON.validate is returning true because the JSON.parse is being called and it returns this error.

An empty string is not valid JSON so no idea why the validate is passing.
 
Upon further reflection clear is probably not the right thing to do with a dropdown anyway. Reset is probably better, or een update to the zero entry. I have resolved the issue for my use. This issue may come up again though and I think the handling of clear in this is incorrect but it is no longer affecting me.
 
Yeah, unintended consequence of switching from the Mootools extended JSON.decode() to native JSON.parse(). The former is a little more tolerant, and returns null rather than erroring out for an empty string. And JSON.validate() is Mootools as well, so it allows empty strings.

I've added a check for empty string (and make it "[]") as of this commit:

https://github.com/Fabrik/fabrik/commit/d5aceb83959c0d3386925062a8d203429e93feba

At some point I'm going to go through the code and wrap all uses of JSON.parse() in try/catch exception handling, get rid of JSON.validate().

-- hugh
 
Hugh, looking at your update is there a typo at line 168? Did you mean list:updated versus liszt:updated?

Maybe you did, it just looks like a typo to me.
 
Nope, liszt:updated is correct. It's the update event for the "Chosen" (enhanced) dropdown menus. More recent versions of Chosen now use 'chosen:updated', but the version shipping with J! is old.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top