Save and reload information from HTML:Dialog

I am wondering how one would save the info from the HTML:dialog UI

If the user wants to edit the information later the information needs to be loaded onto the form.
This is just a small example of what the UI looks like.
Any ideas?

We have covered this multiple times here in this category.

Basically, you would store the data in an AttributeDcitionary onto the garage component.

When the user needs to edit the data, you convert the dictionary to a Ruby Hash instance, then convert it to a JSON Object string and pass it to the dialog. A JS function can then stuff the values from the JS Object into your edit fields.

After the changes are made, the reverse is done. Ie, the JS Object is updated from the values on the form, and the JS Object is passed back to Ruby which automatically converts it back to a Ruby Hash. This hash can then be used to update the attribute dictionary attached to the garage instance in the model using:

data_hash.each { |key, val| data_dict[key.to_s]= val }

See the (collapsed) example go() method at the bottom of this post:
HTML How to delete a line with a text field and button when the button is clicked - #29 by DanRathbun

Or also a condensed general example here:
`UI::HtmlDialog`: global `sketchup` object in dialog has no callbacks when viewing page served remotely after being linked from a local html file · Issue #646 · SketchUp/api-issue-tracker · GitHub

I also discuss it at length in this topic:
Html dialog box to set and get information - Developers / Ruby API - SketchUp Community

1 Like