Ok,
I've got it!! I made a few design decisions which should be reasonably documented in the code, but I've enclosed a fully working example below for submitting forms that works on a Mac and a Windows system.
The example below presents a single form with a radio buttons and checkboxes and after selecting them how you desire and hitting submit all of the settings are sent one by one. To get around the asynchronous/synchronous problem, I essentially have message passing between Ruby and JavaScript to force sending one option at a time (making both Operating Systems act asynchronously) from a options list. It should be quite easy to extend from here.
Here is the HTML/JavaScript Code:
<html>
<body >
Multi-Platform WebDialog form submission test<br><br>
<form name="stuff">
Favorite Food;<br>
<input type="radio" name="food" value="Pizza">Pizza<br>
<input type="radio" name="food" value="Hotdogs">Hotdogs<br>
<br>Favorite Animals;<br>
<input type="checkbox" id="a_cat" value="a_cat">Cat<br>
<input type="checkbox" id="a_dog" value="a_dog">Dog<br>
<input type="checkbox" id="a_squirrel" value="a_squirrel">Squirrel<br>
<input type="button" value="Submit" onclick="sendformdata()">
</form>
<script>
var options = {}; // object that stores all of our settings
//Sends a mesage to SU / Ruby
function call_ruby( callback_name, message ) {
window.location = 'skp;' + callback_name + '@' + message;
}
//Add a checkbox value to the options object
function add_checkbox_data(var_str) {
if (document.getElementById(var_str).checked) {
options[var_str] = "1";
} else {
options[var_str] = "0";
}
}
//Add a radio button value to the options object
function add_radio_data(field) {
//Get the field data
var ps = document.getElementsByName(field);
for (var i = 0, length = ps.length; i < length; i++) {
if (ps[i].checked) {
// store value in our object
options[field] = ps[i].value;
// only one radio can be logically checked, don't check the rest
break;
}
}
}
//Send a single setting to SU, callbacks will come and get the rest
function send_setting()
{
var size = 0, key;
var seting, value;
for (key in options) {
if (options.hasOwnProperty(key)) size++;
}
if (size > 0) {
for (setting in options) break; // Get the first setting
value = options[setting];
delete options[setting];
call_ruby(setting, value);
} else {
call_ruby("submit", 1);
}
}
function sendformdata()
{
add_radio_data("food");
//The checkbox options all have unique names to simplify storage in 'options' receipt at the SU end (more callback handlers needed though)
//Could have concatenated all check options into a string, sent them as a single submit and parsed the string at the SU end too
add_checkbox_data("a_cat");
add_checkbox_data("a_dog");
add_checkbox_data("a_squirrel");
//Send the first setting to SU, the callbacks will get the rest
send_setting();
}
</script>
</body>
<html>
Here is the Ruby Code:
@d = nil
@d = UI;;WebDialog.new("Test", true, "", 800, 800, 200, 200, true)
htmlset = File.join( File.dirname(__FILE__), "test.html" )
@d.set_file( htmlset )
#set the callback for the radiobuttons
@d.add_action_callback('food') { |dialog, params|
puts '>> Food; ' + params
@d.execute_script('send_setting();') #check for more settings to send
}
@d.add_action_callback('a_cat') { |dialog, params|
puts '>> Animal; Cat - ' + params
@d.execute_script('send_setting();') #check for more settings to send
}
@d.add_action_callback('a_dog') { |dialog, params|
puts '>> Animal; Dog - ' + params
@d.execute_script('send_setting();') #check for more settings to send
}
@d.add_action_callback('a_squirrel') { |dialog, params|
puts '>> Animal; Squirrel - ' + params
@d.execute_script('send_setting();') #check for more settings to send
}
#Make the window persistant on top of SU
RUBY_PLATFORM =~ /(darwin)/ ? @d.show_modal() ; @d.show
Thanks to all for the advice along the way.
Sincerely, Paul