Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to setSize for GlideModalForm?

Yuva
Giga Contributor

I have tried OOB setSize method but it didn't work. Could you please share your inputs or suggestions on how to set Size for GlideModalForm?

Thanks,

Yuva

7 REPLIES 7

Yuva
Giga Contributor

Hi,



I tried setDialogSize(w,h) but it didnt work.



Thanks,


Yuva


The correct way to use it as below


setDialogSize: function(w, h) {


  this.setDialogWidth(w);


  this.setDialogHeight(h);


  },



  setDialogWidth: function(w) {


  this.dialogWidth = w;


  },



  setDialogHeight: function(h) {


  this.dialogHeight = h;


  },


thanks sergiu.panaite


Joe72
Tera Contributor

Alas, DOM manipulation is the only way to accomplish a resize with GlideModalForm. If you're going to go in this direction, make sure to use the setOnloadCallback function:

gm.setOnloadCallback(function() {
   //I like to remove the page timing div to make the modal cleaner
   jQuery("#dialog_frame")[0].contentWindow.jQuery("#page_timing_div").hide();
   //Resize the modal window
   jQuery(".modal-content").css("width", "50%").css("margin", "0 auto");
});
gm.render()

Of course, that will cause the window to resize after it's already been loaded, which doesn't look great. So if you're going to head down this direction, I would probably inject the css first to avoid seeing the resize at all.

Here's a UI Macro that accomplishes this. (Macros/Formatters are a great way to introduce CSS to forms.)

<span class="btn btn-default icon-add" title="Enter a Task Order" onclick="openNewTaskOrder()" />

<style>
   #u_task_order .modal-content { width: 50% !important; margin: 0 auto !important;
</style>		

<script>
   function openNewTaskOrder() {			
      var gm = new GlideModalForm('Enter new Task Order', 'u_task_order');
      gm.render();
   }
</script>