Currently, I am utilizing JsonForm which can be found at https://github.com/joshfire/jsonform/wiki#wiki-getting-started.
My objective is to load a form schema into $('form').Jsonfrom() from an external .txt file.
To achieve this, I decided to load the schema into my .html file using ajax, store it in a javascript variable, and then trigger $('form').Jsonfrom() with a click event.
This is the code snippet I have been working on:
<script>
#Load in .txt to javascript variable using ajax
var stringData = $.ajax({
url: "schema.txt",
async: false
}).responseText;
#Check that the file loads correctly. - Have verified this works.
#alert(stringData);
#Upon clicking text within a <p> wrapper, execute jsonForm function.
$(document).ready(function(){
$("p").click(function(){
$('form').jsonForm(stringData)
});
});
</script>
The error message reported in Firebug reads as follows:
"TypeError: this.formDesc.schema is undefined"
Here is my stack trace for reference:
I suspect that the issue might lie in loading the .txt file via ajax.
However, when I uncomment: alert(stringData); . . . the schema for the form displays perfectly.
Demonstrated here:
Additionally, there doesn't appear to be any problem with the schema itself since I tried directly inserting it into $('form').Jsonfrom("here")
and it functions without issues.