WebDialog input text and the single quote.
-
Is there some reason that a single quote can not be used in a input text box in a webdialog?
I was working on a WebDialog and attempted to enter a value in feet rather than inches but got an error due to the data string from a submit button being empty. It seems that 60" is ok but 5' isn't. However 5' is ok.
The following code can be used to demonstrate.
def webdialog() @dlg=UI;;WebDialog.new("TESTING", false,"WDID",300,200,10,10,true) @dlg.set_html( "<html> <body> <form action='skp;wd_data@'> <input type='text' name='tb1' value='60' size=1 > TextBox One</input><br> <input type='submit' name='submit' value='Go' /> </form> </body> </html>" ) RUBY_PLATFORM =~ /(darwin)/ ? @dlg.show_modal() ; @dlg.show() @dlg.add_action_callback("wd_data") {|d,p| if p puts p else puts "p was empty" end } end
-
The reason you can't use ' is because its an escape character in your string:
Whenever you wan't to get element value, usedlg.get_element_value('element_id')
It handles escape characters like a charm.So, if want to get your element value whenever "ws_data" is called, do this:
<span class="syntaxdefault"><br /></span><span class="syntaxkeyword">@</span><span class="syntaxdefault">dlg</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_action_callback</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"wd_data"</span><span class="syntaxkeyword">){</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">d</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">p</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> text </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_element_value</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'tb1'</span><span class="syntaxkeyword">)<br />} </span><span class="syntaxdefault"></span>
Make sure to avoid passing text value to the callback; this will prevent the error.
-
Thanks Anton, that does work. Early on I had problems using .get_element_value so I never thought about it again opting to get the values from the "p" string. I guess it was just beginners bad luck.
-
@sdmitch said:
Early on I had problems using .get_element_value so I never thought about it again opting to get the values from the "p" string.
What problem was that?
I also utilize get_element_value for callbacks from JS to Ruby. I use a bridge that convert basic Ruby and JS objects back and forth with synchronous callback on both platform. Using an input element as data transfer is my standard technique. -
@tt_su said:
@sdmitch said:
Early on I had problems using .get_element_value so I never thought about it again opting to get the values from the "p" string.
What problem was that?
I also utilize get_element_value for callbacks from JS to Ruby. I use a bridge that convert basic Ruby and JS objects back and forth with synchronous callback on both platform. Using an input element as data transfer is my standard technique.It was very early in my plugin career and involved radio buttons. As soon as I found something else that worked, I never tried using it again. I'm sure it was mostly, if not all, operator error.
Advertisement