-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String to Function #12
Comments
PR is welcome. 2015-06-09 1:20 GMT+08:00 Rusty Gerard [email protected]:
Ulion |
My workaround is to use a reviver before initializing the JSON Form: // Reviver method for JSON.parse to coerce strings to other objects
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Example:_Using_the_reviver_parameter
function preprocessJson(k, v) {
// Convert strings to functions
if (typeof v === "string" && v.startsWith("function")) {
console.log("Reviving function: " + v);
eval("var f = " + v);
return f;
}
return v;
} var myForm = JSON.parse('{...}', preprocessJson);
$('form').jsonForm(myForm); If this is useful I can update the wiki. Thoughts? |
It's cool, please do that. and maybe also the original repo's wiki please. 2015-06-17 5:12 GMT+08:00 Rusty Gerard [email protected]:
Ulion |
Sorry, which wiki are you referring to? I'm only aware of https://github.com/joshfire/jsonform/wiki |
Ok, it's cool, I thought I had one, never mind. use the one which peoples 2015-06-18 5:27 GMT+08:00 Rusty Gerard [email protected]:
Ulion |
The examples for event handlers will not pass through a strict JSON parser, which makes it impossible to store the schema as pure json (e.g. external to the app, or to be passed around between components).
http://ulion.github.io/jsonform/playground/?example=events
A "string to function" feature would be extremely useful for this. For example, instead of:
...we could write:
...or even just statements that could be wrapped in an
eval
call, instead of a full-fledged function:The text was updated successfully, but these errors were encountered: