Titanium Community Questions & Answer Archive

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

Ti.App.fireEvent triggering many times for iPhone application.

Hello all,
Am developing a iPhone application in which upon click of a button in webview(html) it calls the function in my temp.js. Everything works fine, but the function is trigged 2times.

I've gone through other Q&A and to be more specific i found the solution for android with this ticket

http://developer.appcelerator.com/question/11211/webview-fireevent

My titanium version is 1.3.0 and the iPhone sdks is 3.1

Can you please suggest a solution for the same in iPhone?

Thanks in advance.

— asked November 16th 2010 by Sathishkumar Durai
  • iphone
  • ti.app.fireevent
  • webview
2 Comments
  • it would be helpful if you posted code with your questions

    — commented November 16th 2010 by Aaron Saunders
  • hal agrees with Aaron completely! :)

    — commented November 16th 2010 by Paul Dowsett

4 Answers

  • Accepted Answer

    Sathishkumar

    The ticket you have referenced is very old, and things have moved on since then. In fact the bug described was fixed.

    The only way to answer this is if you provide some stripped-down working code (simple code that works without further modification) that demonstrates the situation you describe.

    I assure you, your problems would be answered so much quicker every single time if you are able to bear this advice in mind.

    I could speculate that the behaviour you have observed is the normal effect of event bubbling, but without code that would be a total guess.

    — answered November 16th 2010 by Paul Dowsett
    permalink
    0 Comments
  • @Hal H

    Thanks for your advice and the following describes a prototype of my code snippet.

    1. tmlogin.html - local file available in Resources Folder.

    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>LoginForm</title>
    
            <script type="text/javascript">
                function buttonOkClick()
                {
                    var un;
                    var ps;
                    var a;
                    var b;
                    un = (document.getElementById("inputUserName"));
                    ps = (document.getElementById("inputPassword"));
    
                    a = un.value;
                    b = ps.value;
                    Ti.App.fireEvent('info',{a:a,b:b});
                }
            </script>
        </head>
        <body>
                <input type="text" id="inputUserName" />
                <input type="password" id="inputPassword" />
                <input type="button" value="Log In" onclick="buttonOkClick()"/>
        </body>
    </html>
    

    2. getvalue.js - local file available in Resources Folder.

    var win = Titanium.UI.currentWindow;
    var username;
    var password;                                                                                
    var data = [{title:'CPF Cloud Login', hasChild:true, url:'tmlogin.html'}];    
    
    var tableview = Titanium.UI.createTableView({
        data:data,
    });
    
    tableview.addEventListener('click', function(e)
    {                           
       var rowdata = e.rowData;
       var w = Ti.UI.createWindow();
       var webview = Ti.UI.createWebView();
    
       webview.url = rowdata.url;
       w.add(webview);
       win.tab.open(w);        
       Ti.App.addEventListener('info', function(e){
            username = e.a;
            password = e.b;
                    alert(username);
                    alert(password);
            invoker(); calls further implementation using XHR SOAP
            });
    });
    win.add(tableview);
    

    Here my alerts and invoker() functions are triggered twice and hence the every further step inside invoker() is happening twice. Can you please suggest a solution for this problem. I've gone thro most of the Q&A regarding the same issue but not able to find the answer.

    — answered November 17th 2010 by Sathishkumar Durai
    permalink
    1 Comment
    • Sathishkumar

      Unless you provide complete stripped-down (remove all the complex or unnecessary functionality - use Ti.API.info() output instead) working code, including app.js and the required window creation lines, then it's difficult to say what is causing your issue.

      — commented November 17th 2010 by Paul Dowsett
  • @Hal H. Thanks for your help. I used Ti.API.info() for displaying my results and everything works fine.

    Also i figured out that multiple or too many use of alert() will crash the application because it was not the fault of fire event which is crashing my application but too many usage of alert() once i removed all those alert() it worked fine. Instead usage of Ti.API.info() is better. :-)

    — answered November 18th 2010 by Sathishkumar Durai
    permalink
    0 Comments
  • @Hal H. Thanks for your help. I used Ti.API.info() for displaying my results and everything works fine.

    Also i figured out that multiple or too many use of alert() will crash the application because it was not the fault of fire event which is crashing my application but too many usage of alert() once i removed all those alert() it worked fine. Instead usage of Ti.API.info() is better. :-)

    — answered November 18th 2010 by Sathishkumar Durai
    permalink
    0 Comments
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.