Skip to content

Commit

Permalink
Merge pull request #23 from stephenmcm/fix-select2
Browse files Browse the repository at this point in the history
Fix quickaddnew sometimes getting entwined twice
  • Loading branch information
sheadawson committed Jul 6, 2015
2 parents 8d3bb2e + 75d1ad6 commit a2b7870
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions javascript/quickaddnew.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,25 @@ jQuery.entwine("quickaddnew", function($) {
URL: null,
onmatch: function() {
var self = this;


//Check to see if quickaddnew has been bound to this field before, sometimes jQuery plugins like Select2
//will trigger a binding a second time that we don't want.
if($(this).parents().children('.quickaddnew-button').length > 0) {
return;
}
// create add new button
var button = $("<button />")
.addClass()
.text(ss.i18n._t('QUICKADDNEW.AddNew'))
.attr('href', '#')
.addClass("quickaddnew-button ss-ui-button ss-ui-button-small")
.appendTo(self.parents('div:first'));

// create dialog
var dialog = $("<div />")
.addClass("quickaddnew-dialog")
.appendTo(self.parents('div:first'));

.appendTo(self.parents('div:first'));
this.setDialog(dialog);

// set URL
Expand Down Expand Up @@ -87,14 +92,16 @@ jQuery.entwine("quickaddnew", function($) {

showDialog: function(url) {
var dlg = this.getDialog();

dlg.empty().dialog("open").parent().addClass("loading");

dlg.load(this.getURL(), function(){
dlg.parent().removeClass("loading");
// set focus to first input element
dlg.find('form :input:visible:enabled:first').focus();
});
// Check to see we have a dialog, other jquery plugins like Select2 can get bound to by accident
if (dlg !== null) {
dlg.empty().dialog("open").parent().addClass("loading");

dlg.load(this.getURL(), function(){
dlg.parent().removeClass("loading");
// set focus to first input element
dlg.find('form :input:visible:enabled:first').focus();
});
}
}
});
});
Expand Down

0 comments on commit a2b7870

Please sign in to comment.