Inline JS within Popup

  • 1
  • Question
  • Updated 2 years ago
  • Answered
I have this inline JS code which I use for drag and drop functionality within table. It works fine when the table is on the main page but now I am trying to execute this within a popup. Any tips?

(function(skuid){var $ = skuid.$;
$(document.body).one('pageload',function(){
var component = skuid.$C('sk-3MxwBj-240'),
   listContents = component && component.element.find('.nx-list-contents');
listContents.sortable({
   placeholder: "ui-state-highlight",
   stop: function( event, ui ) {
       var data = ui.item.data('object'),
           model = data.list.model,
           movedRow = data.row,
           target = $(event.target);
       
       target.children().each(function(index,tr){
           var row =  $(tr).data('object').row,
               order = row.Order__c;
          if (index + 1 !== order) {
              model.updateRow(row,'Order__c',index+1,{initiatorId:component._GUID});
          }
       });
           
   }
});
});
})(skuid);
Photo of DannyS

DannyS

  • 294 Points 250 badge 2x thumb

Posted 2 years ago

  • 1
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,050 Points 10k badge 2x thumb
Hi Danny. Does the code above reference a unique ID for the table component? "sk-3MxwBj-240" may need to be changed if it should refer to a different component in the popup.
(Edited)
Photo of DannyS

DannyS

  • 294 Points 250 badge 2x thumb
yes that is referencing the new table within the popup.  I believe the issue is that this JS is inline which means it executes after the main pages loads where as I need this to execute after the popup loads.
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,050 Points 10k badge 2x thumb
Okay. In that case, you might need to set up a second (matching) JS inline Snippet for the popup, and trigger that as one of the actions that happens when the popup is opened. Is the popup showing a page include, or is it all part of one page?
(Edited)
Photo of DannyS

DannyS

  • 294 Points 250 badge 2x thumb
I tried that as well. I have a button which when clicked opens the popup.  The action after that renders a snippet.  That did not seem to work either. Let me know if you were referring to a different type of action.
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,050 Points 10k badge 2x thumb
That's along the lines of what I had imagined. You may also need to remove or replace the line
$(document.body).one('pageload',function(){
since the pageload event doesn't happen when the button is clicked.
(Edited)
Photo of DannyS

DannyS

  • 294 Points 250 badge 2x thumb
Ok I will try this thanks
Photo of DannyS

DannyS

  • 294 Points 250 badge 2x thumb
That worked thanks!