Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 11    Views: 118

tompos
Veteran developer
Profile
Posts: 127
Reg: Oct 19, 2013
Würzburg
7,370
05/06/14 08:10 AM (10 years ago)

Plugin with childItems... control panel problem

I am currently developing a plugin where users can input a zip code for each child item. The How-To guide by nadthevlad is great... I implemented the changes for my purposes on my self-hosted server. Fine. However, when I try to input a zip number with a leading zero (which is the valid zip code in some regions in germany), I get a JSON error. A problem occurred while fetching some data (1). The results were not valid JSON. {"result":"success", "startIndex":"0", "totalNumberOfChildItems":"2", "childItems":[ {"itemId" : "DC02CAE7A43E948928BA328","itemType" : "BT_menuItem","myZip" : 01234,"city" : "Berlin", "orderIndex":"1"}, Before changing the zip code from 12345 to 01234, the corresponding JSON code was "myZip" : "12345". After the change, the quote signs are gone... and that may be the problem. In that state the text input can not be changed back, because of the JSON error. ... so my question. Do I have to declare the text input field in the "childItems.html" differently in order to keep all characters and to produce valid JSON? Btw, I get the same error message if I input a text with a leading "0" in a quiz question using the NAD flash card plugin. The self-hosted software is 3.0.0 (no update necessary). Thanks Thomas
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
05/06/14 08:27 AM (10 years ago)
How/where are you retrieving the json value. Is the retrieval in javascript? this is a json number "myZip" : 01234 this is a json string "myZip" : "12345"
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
05/06/14 12:54 PM (10 years ago)
one way that helps me with plugins is downloading the self hosted package of other plugins.that's the actual package the developer sent to buzztouch.
 
tompos
Veteran developer
Profile
Posts: 127
Reg: Oct 19, 2013
Würzburg
7,370
like
05/06/14 01:17 PM (10 years ago)
@nadthevlad The error message is displayed when I "refresh" the list of child items in the control panel. So this happens well before I try to retrieve the json data from my app. The error location can be found in your "childItems.html" file that you provided as an example for the How-To documentation: var res = fnExecuteBackendCommand("getChildItems"); var json = null; try{ json = $.parseJSON(res); }catch(err){ } //json loaded... if(json == null){ $("#childItemLoadingMessage").html("<div style='color:red;padding:5px;'>A problem occurred while fetching some data (1). The results were not valid JSON.<br>" + res + "</div>"); .... You mention the difference between json string and json number. It seems as if my data are changed to a json number internally when I start the input with a "0". The input field was declared before as <div style='padding-top:5px;'> <b>Zip code</b><br/> <input name='myZip' id='myZip' type='textarea' value="" style='width:500px; ' /> </div> @CMCOFFEE Thanks, you are right. As I mentioned before the same problem happened when I used the example by nadthevlad.
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
05/06/14 03:15 PM (10 years ago)
Can you post your childItems.html (with an s). The issue will probably be with the json down in the script section. I tested my quiz plugin and it accepts leading zeros as an input and outputs them as a string with the zeros still intact. "questionText": "0000011111", One thing I would check is on page 11. Where is says var front_side = "" Those parentheses are important because we are telling javascript we want a string and not a number.
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
05/06/14 03:16 PM (10 years ago)
The dangers of a loosely typed language.
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
05/06/14 03:45 PM (10 years ago)
And if you can't post it you can always email me.
 
tompos
Veteran developer
Profile
Posts: 127
Reg: Oct 19, 2013
Würzburg
7,370
like
05/07/14 01:51 AM (10 years ago)
The corresponding part of my childItems.html file is var myZip = ""; if(obj["myZip"] != ""){ myZip = obj["myZip"]; } ... I just changed your two variables front_side and back_side to my variables myZip, city. One funny thing: I get the same error when I use the "www.buzztouch.com" server and when I use your example ("questionText": "0000011111") for your quiz plugin. So I guess it has nothing to do with my self hosted software. So there might be a problem because I am using a specific browser (safari), from a specific country...? I any case, this is strange... I send you some files per email. Thanks for your help Thomas
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
05/07/14 09:25 AM (10 years ago)
Out of curiosity are magic quotes on in your php settings?
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
05/07/14 11:05 AM (10 years ago)
I am seeing it in mine now. Needed to refresh the page.
 
tompos
Veteran developer
Profile
Posts: 127
Reg: Oct 19, 2013
Würzburg
7,370
like
05/07/14 01:25 PM (10 years ago)
magic quotes... should be in the php settings of my self hosted server... I have to look at that. but as the problem happens for the buzztouch.com server as well, it should be a more general problem...
 
tompos
Veteran developer
Profile
Posts: 127
Reg: Oct 19, 2013
Würzburg
7,370
like
05/08/14 12:38 AM (10 years ago)
magic quotes... should be in the php settings of my self hosted server... I have to look at that. but as the problem happens for the buzztouch.com server as well, it should be a more general problem...
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.