Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Modal and Centered on Titanium Desktop

On Titanium Desktop, I have been trying to open a modal dialog upon a click of a button, but have not been able to find a way of doing it.

As a workaround, I decided to use the web trick of placing a div over my main window to prevent clicking and open the dialog as "always on top", but the problem now is that any alert or confirm open in the context of the main window, thus appearing behind my "on top" dialog.

So back to the drawing board and formally asking:

In Titanium Desktop, how can I open a modal and centered dialog box upon the click of a button?

Thanks a bunch!

R

— asked September 17th 2010 by Ricardo Alcocer
  • centered
  • desktop
  • modal
  • window
0 Comments

6 Answers

  • Ok, so to bring this to a conclusion, I'll document a few hacks I did to reach my goal.

    In my case, it made no difference using showDialog vs createWindow. Don't really know if there are any advantages, but I settled with createWindow.

    I'm not setting the window as TopMost, because it caused any alerts or confirms to show underneath the topmost window.

    Centering I will work by creating a formula which will take into consideration screen.width, screen.height, and the dimensions of the forms I have floating around.

    Now, to simulate a Modal window, since I was able to confirm that Titanium Desktop doesn't have a native way of doing it, what I'm doing is activating a fullscreen transparent div on top of my main window, which will prevent any clicking while my "modal" window is displayed.

    CSS I'm using for this is:

    body{
        height: 100%
    }
    
    div.fullscreen{
        display:block;
        visibility: hidden;
    
        /*set the div in the top-left corner of the screen*/
        position:absolute;
        top:0;
        left:0;
    
        /*set the width and height to 100% of the screen*/
        width:100%;
        height:100%;
    }
    

    When I open my window, I set the DIV to visibility: 'visible'.
    Also, I set an event listener to this div on it's click event, and trigger a "focus" event on my "modal" window. When my "modal" window closes, I set the DIV back to visibility: 'hidden', thus allowing me to work with the main window again.

    There you have it. A hack to create "modal" functionality.

    -R

    — answered September 18th 2010 by Ricardo Alcocer
    permalink
    1 Comment
    • $('#overlay').click(function(){modalWindow.focus();});
      

      — commented January 26th 2012 by Nine Ijof
  • if you need just a simple dialog you should use:
    Titanium.UI.showDialog()
    This methos takes an object as argument, but i cannot find any good docs right now. docs are a bit tricky linked / to read.

    — answered September 17th 2010 by Michael Stuhr
    permalink
    0 Comments
  • Thanks Michael. I'm definitely getting closer. showDialog takes care of the centering, but I'm still not able to get it as a modal dialog. Here the open code:

    var w = Titanium.UI.showDialog({
            url:'app://view.html',
            width: 400,
            height:200,
            resizable:false,
            maximizable:false,
            minimizable:false
        });
    

    I tried setting topmost:true and modal:true to no avail.

    R

    — answered September 17th 2010 by Ricardo Alcocer
    permalink
    0 Comments
  • oh, i was under the impression that you'd use a native UI-Dialog.
    since we do not know the exact properties of a Dialog, you probably should use "Titanium.UI.createWindow()" which at least has "topmost", but i bet you need a "modal=true" here too ^:-)

    — answered September 17th 2010 by Michael Stuhr
    permalink
    0 Comments
  • maybe you should try: setModal(true) on the Dialog / Window. in a small project i did, i hab a similar problem, where the docs said createSth({foo:bar}) but that got never recognized. so i tried the same funtion after it has been created, and it worked.

    — answered September 17th 2010 by Michael Stuhr
    permalink
    0 Comments
  • Michael,

    Tried setModal(true) both right after the createDialog and also inside the actual file and didn't work.

    Topmost does work on createWindow, but any subsequent alert or confirm will show behind this topmost window…and though it comes to mind to create my own alerts and confirms via createWindow, besides being a nasty hack, I don't know how it will behave trying to open a topmost window on top of a topmost window.

    My app has a grid with data. What I want to do is to be able to click on an item, and get its details in a modal window. There must be a way of doing this. I would hate to have to do it using javascript/dhtml lightboxes.

    R

    — answered September 17th 2010 by Ricardo Alcocer
    permalink
    1 Comment
    • well topmost should always be a "snap-shot" attribute by which i mean: a topmost window just sits topmost on all others and can/should be a parent window, while a modal is to me always a child-window, which behaves like topmost but in respect to it's parent, and not the desktop.

      i'm just trying to make my understanding clear here. maybe the way titanium does it is correct, but i'm under the impression it's a BIG bug + some missing things here.

      the other day someone assumed, that the desktop version only lives because of the builder-tool. i guess he couldn't be more right with that.

      — commented September 17th 2010 by Michael Stuhr
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.