Example html dialog (suite)

Getting non-digits truncated typically happens when a string is parsed into a numeric value. When parsing it directly as Length this shouldn’t be an issue.

It works perfectly fine for me. Just 2 lines of code for string replacement.

And it stops working the second the user writes a ^ in a text field.

1 Like

Nope - already taken care of.

Then again. Use json. Really. Whenever you serialise data, use a common serialization format.


Nope - not interested - I’ve used my solutions since the early 80’s - no issues.

Why change something that isn’t broke (obviously rhetorical)

Boy, not easy to find pertinent example code.


1 Like


1 Like

Yes, saw that. Thanks
Now struggling with read and write from local file.
Tried with Fetch. but of course, I got a Cross origin error.


Search results for “JSON” in Ruby API category

I do think this has to be underlined once more. !!

I’m just trying to get the Html dialog to show the last used values.

rb side
read values from local file √
make a hash with them √
hash.to_json √ json_str => {“thi”:“150”,“hei”:“2222”}.

Something is wrong in the following:

dialog.execute_script(“var jvals = #{json_str};”)

HTML side:
in a script

var Vals = JSON.parse(jvals)
document.getElementById(“thi”).value = Vals.thi
document.getElementById(‘hei’).value = Vals.hei

I’m not an expert, but maybe you need quotes around the interpolated json_str when you pass it to jscript? like

dialog.execute_script(“var jvals = “#{json_str}””)

Strings literals says it will get evaluated if the whole string is in “”

The irony here Steve, is that on Mac, I can just use an array. Pass it to html with a text sub and there it is seen as an array. Works pretty fine.
But not on pc.

I run the following - works on both PC and Mac where data is a string.

script = "from_ruby_( '" << data << "' )"

What if data is a string that contains ' ?


Mine do not - I replace all single quotes with back quotes.

@mariocha You do not really need the JS var jvals. Try …

dialog.execute_script("var Vals = JSON.parse('#{json_str}');")

The outer double quote is for Ruby interpolation.
The single quote around the JSON string is for JavaScript because JSON string data itself uses double quotes.

But you can also do …

dialog.execute_script("var jvals = '#{json_str}';")

Thanks a lot Dan, I really needed a confirmation of one of my many tries.
working on the HTML side now.
Do I need to JSON.parse there ?
does the line. var jvals = ‘#{json_str}’; has to also be in the html ?