soeren
January 26, 2017, 1:53pm
1
This is what @sean.paley also sugested in Escape strings in body of API call . Re-posting here as an idea for a nice feature that it’s difficult to accomplish otherwise. I have used find & replace with some success, but there is a lot you need to take into account. See https://msdn.microsoft.com/en-us/library/dn921889.aspx
Like this package https://www.npmjs.com/package/escape-json-node
mishav
January 26, 2017, 2:46pm
2
There is JSON.stringify(mydodgystuff) available in the browser’s javascript, do you need to escape more than that does?
Partially answering my own question, … there is a bunch of test cases in here, for some gory details of escaping : )
const assert = require('assert');
const escapeJSON = require('../lib/escape-json');
describe('escape-json', () => {
describe('init', () => {
it('should not modify JSON string which is not containing any apostrophes or double quotes', () => {
const escapedJSONString = escapeJSON(
'{"quoteText": "How far that little candle throws its beams! So shines a ' +
'good deed in a naughty world."}'
);
const expectedEscapedJSONString =
'{"quoteText": "How far that little candle throws its beams! So shines a ' +
'good deed in a naughty world."}';
assert.equal(
escapedJSONString,
expectedEscapedJSONString,
'JSON string should not be modified'
);
});
This file has been truncated. show original
soeren
January 26, 2017, 3:10pm
3
Sorry for my ignorance, but how do I access JSON.stringify() from Bubble?
mishav
January 26, 2017, 5:03pm
4
It’s definitely coding … but not necessarily a lot of it.
Basic outline here, to get started:
More complex implementation in the signature pad example, with an app to look at:
There’s a few other examples of using javascript in the forum, worth a search IMO.
Good that you’re aware of onload, note that the first time the javascript runs, the input element likely won’t be ready to be changed. The javascript in the HTML element will run at load, and again every time any dynamic values in it are updated.
I’ll be interested to see if autobindin…
With an input field with placeholder “JSON-string-input”, the HTML code would be something like:
<script type="text/javascript"> if ("pageloaded" === "yes" && "mystring-is-not-empty" === "yes") { $('.bubble-element .Input[placeholder="JSON-string-input"]').val(JSON.stringify("mystring.value")).change(); } </script>
Replacing pageloaded
and mystring-is-not-empty
with dynamic values.
If you try it, I’ll help get it working.
Some of us are fiddling with the new element templates, so this will become a bit easier soon.
NigelG
January 26, 2017, 5:45pm
5
https://wt-nigel_godfrey-gmail_com-0.run.webtask.io/stringify?jvalue=this%20isn%27t%20all%20that%20great%20but%20%22hey%22%20who%20cares
just this … in a webtask.io
module.exports = function(context, cb) {
cb(null, JSON.stringify(context.query.jvalue));
}
soeren
January 26, 2017, 8:46pm
6
Thanks @NigelG and @mishav , I will try it out next week and post an update here with some feedback.
mishav
January 27, 2017, 4:21am
7
A hint as to which method is appropriate, using an API is better if you want the data to stay on the server. Using the browser javascript saves the roundtrip of an extra API call, if using the JSON in response to a user action.