Get form data from webdialogs?
-
Have a look at TextureResizerOptions.htm, it returns all user input on input[type=radio, checkbox or text] using 'name' and 'value' attributes and returns either TRUE/FALSE or string.
I replaced a 'text box' with a block of radio buttons for setting 'goldilocks-resolution' yesterday.
works a charm, [with a little guidance from Aerilius...]Comment out the existing goldilocks code and drop this in to see the results, uses the existing JS unmodified.
<style type="text/css" id="style0">.goldilocks{display;none!important}</style> <br class="goldilocks"/> <input class="goldilocks" type="radio" name="method" value="goldilocks" id="method-goldilocks" /> <label class="goldilocks" for="method-goldilocks" title="Calculates the dimensions depending on the current viewport using the plugin Goldilocks.">Goldilocks resolution;</label> <ul class="goldilocks"> <li class="flt-r"> <label for="goldilocks-resolution" id="goldi-bg">low <input name="goldilocks-resolution" id="goldi-1" class="num goldilocks" type="radio" value="1"> <input name="goldilocks-resolution" id="goldi-2" class="num goldilocks" type="radio" value="2"> <input name="goldilocks-resolution" id="goldi-3" class="num goldilocks" type="radio" value="3"> <input name="goldilocks-resolution" id="goldi-4" class="num goldilocks" type="radio" value="4"> <input name="goldilocks-resolution" id="goldi-5" class="num goldilocks" type="radio" value="5"> <input name="goldilocks-resolution" id="goldi-6" class="num goldilocks" type="radio" value="6"> <input name="goldilocks-resolution" id="goldi-7" class="num goldilocks" type="radio" value="7"> <input name="goldilocks-resolution" id="goldi-8" class="num goldilocks" type="radio" value="8"> high</label> </li><br />
john
PS. you'll need TextureResizer and Goldilocks for it to show. -
So sending 1 large string object(JSON or whatever)in 1 go, to SKP ruby , is the way to go in all circumstances?
(Like texture resizer is doing). And not several get_element_values in callback.It seams to me there are 2 ways of doing it, and that is confusing which one to choose.
I've seen topic about the subject in this forum and its not easy determin whoose right..Get_element_value method is more straightforward and easier to understand than converting JSON.
Maybe thats why JS noobies tend to go with this method first.@unknownuser said:
WebDialog.post_url ??
Is it a question if someone tried it? Or do you know it will work
-
@jolran said:
@unknownuser said:
WebDialog.post_url ??
Is it a question if someone tried it? Or do you know it will work
A Question.
It may need to use the standard CGI lib from a full Ruby install.
-
Common Gateway Interface (CGI)?
@unknownuser said:
It may need to use the standard CGI lib from a full Ruby install.
Ouch. That could be a lot to ask of users.
- yet another thing to get into.
Thanks for the head up anyway, Dan.
-
@adamb said:
I have nothing to add other than Chris's avatar image makes me feel distinctly unwell.
What about my avatar could possibly make you feel unwell?
For some unknown reason, suddenly the whole board was inundated with masks for new user icons one day, and one permanently left its mark on me. Actually I do need to redo my avatar and trim down the belly a little. I lost 50lbs recently, so it shouldn't bulge quite so much
Oh yeah, and I did finally get what I needed working. It took me a while to figure out what it was that I needed. But I did decide to use jquery. I needed a multiple select list, and when the user clicks the submit button, I've got an
onclick='submit_form1'
that calls my js function. Then the js function uses jquery to gather all selected values into a string and sends it to SketchUp. This works well for my mind to be able to follow the logic of it.function submit_form1(){ var myarr = []; var str = '' myarr = $("select option;selected"); $("select option;selected").each(function () { str += $(this).text() + ","; }); alert(str); query = 'skp;select_scenes@' + str; window.location.href = query; }
-
Aha! Scene manager
Glad you sorted it out
-
@chris fullmer said:
> $("select option;selected").each(function () { > str += $(this).text() + ","; > }); >
Be careful that your options don't contain commas.
-
Ah, that did not cross my mind. All my "options" values are scene names. So I'll have to check if scene names can contain commas - if so, I'll have to re-think my delimiter. Thanks!
EDIT - yes, scene names can contain commas. What delimiter do I use then? I'm stumped. Do I forcibly remove commas from the user's scene names before processing? That seems like a bad idea.
-
@chris fullmer said:
Do I forcibly remove commas from the user's scene names before processing? That seems like a bad idea.
No, that's not good. That's making the user work for the computer instead of the computer working for the user.How about
||
?
Much more unlikely to appear in a tab.
Though, there is still a risk of it.You could make a escape character scheme. Escape | with | - then off course you also need to escape \ with \ .
This example is all Ruby, but you can easily port it to JS.
Escape a string:
string = page.name string.gsub!('\\', '\\\\') string.gsub!('|', '\\|')
Restore it:
string.gsub!('\\\\', '\\') string.gsub!('\\|', '|')
If you do it for all input - output then you will be safe that there will never be any conflict.
-
Could you use 'tab' as the delimiter - these are never going to appear in a Scene name ?
$("select option;selected").each(function () { str += $(this).text() + "\t"; });
Then on the Ruby side use
chosen=str.split("\t")
to make an array of the items ??? -
@tig said:
Could you use 'tab' as the delimiter - these are never going to appear in a Scene name ?
Actually they can. Paste a string containing Tab and it'll be there. Or it can be added via some Ruby script...
pages[0].name = "Foo\tBar"
-
OK how about 'newline' ?
$("select option;selected").each(function () { str += $(this).text() + "\n"; });
then in Ruby
chosen=str.split("\n")
?
Or even \r or \f ? -
That would be even more unlikely to appear, but it's still possible - for instance the Ruby API will allow
\n
. Who knows what an importer for instance might put in there when importing from some random data. Or if it takes input from somewhere without sanitising.I mean, it's unlikely, but still possible. Where as using an escape character scheme would make it 100% safe. And it's a simple thing as well.
<span class="syntaxdefault">def escape_pipe</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> string </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> string</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">gsub</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'\\'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'\\\\'</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">gsub</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'|'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'\\|'</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">end<br /><br />def restore_pipe</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> string </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> string</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">gsub</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'\\\\'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'\\'</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">string</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">gsub</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'\\|'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'|'</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">end<br /></span>
-
so far there is no elegant solution for it!
Javascript may be useful but have problem when handling mutibyte characters -
@bigcatln said:
so far there is no elegant solution for it!
Javascript may be useful but have problem when handling mutibyte charactersEh? Javascript is unicode compatible... Ruby on the other hand, the 1.8 branch we're stuck with in SU, only deal with strings as ASCII characters.
-
The problem is JSON doen't support Multibyte characters in fact. when you restore Json str from javascript in ruby,it can't be handled correctly
-
@bigcatln said:
The problem is JSON doen't support Multibyte characters in fact. when you restore Json str from javascript in ruby,it can't be handled correctly
But that's a problem with Ruby 1.8 which only handle ASCII strings - and not a problem with JavaScript...
-
I always do as chris does:
collect in one string, send to SU, split there if needed
Advertisement