I've been having some trouble creating a confirmer dialog using tw2.jqplugins.ui.DialogWidget. I have it working by specifying the dialog's buttons in Javascript instead of tw2, but I'd like to understand why tw2 isn't working.
In the first example, I specify the buttons for the dialog as one of the dialog's options using tw2. When I click one of the dialog's buttons I get "TypeError: d.click.apply is not a function" in the Firebug console.
from tw2.jqplugins.ui import DialogWidget
confirmDialog = DialogWidget(id='confirm-dialog',
options={'modal' : True,
'autoOpen' : False,
'title' : 'Confirm save for later',
'buttons' : [ { 'text': "Save", 'click': 'function() { $( this).dialog( "close" ); $("form").submit(); }' },
{ 'text': "Cancel", 'click': 'function() { $( this ).dialog( "close" ); }' } ] })
In the second example I omit the 'buttons' option above, and add the buttons in a Javascript function. That function gets called when the containing form's submit button is clicked. This works.
function addButtonsAndOpen(dialogSelector) {
$(dialogSelector).dialog({ buttons: [ { text: "Save", click: function() { $( this).dialog( "close" ); $("form").submit(); } },
{ text: "Cancel", click: function() { $( this ).dialog( "close" ); } } ] });
$(dialogSelector).dialog("open");
}
js1 = 'addButtonsAndOpen("#confirm-dialog-later"); return false;'
submit1 = twf.SubmitButton(name='saveForLater', value='Save for later', attrs={'onClick' : js1 })
Am I specifying the button's 'click' functions incorrectly in the first example? Or is this a tw2.jqplugins problem?
Any help appreciated,
Matthew