sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [FIXED!!!] Anyone seen this web dialog bug?

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 5 Posters 1.9k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      todd burch
      last edited by

      I'll also add that if I code a SketchUp UI.messagebox instead of a javascript alert in the rescue clause to report the invalid value, I get the same erroneous behavior.

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        Never seen it.
        Got the code to poke about?

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • T Offline
          todd burch
          last edited by

          Here's my test case that does not show the error. I think perhaps having more callbacks in the mix might make it happen, I just haven't spent the time to go there yet.

          require 'sketchup.rb'
          
          myhtml =<<DATA
          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html" charset="utf-8"/> 
          <script>
          function toHex(str) { 
          	var hex   = '' ;
          	var achar = '' ; 
          	var bchar = '' ; 
          	var cchar = '' ; 
          	for (var i = 0 ; i < str.length ; i++ ) {
          		cchar = str.charCodeAt(i).toString(16) ; 
          		if (cchar.length == 1) cchar = '0' + cchar ; 
          		hex += '' + cchar.toUpperCase() ;
          	}
          	return hex ;
          }
          </script>
          </head>
          <body>  
          <form name='myform'> 
          <label for='input_field'>Enter Value</label>
          <input 	
          	id='ifield' 
          	name='myfield'  
          	type='text' 
          	maxlength='10' 
          	size='10'
          >
          <br />
          <input 
          	type='button'
          	value='OK'
          	onclick="window.location='skp;setvalue@' + toHex(document.getElementById('ifield').value);"
          >
          </form>
          </body>
          </html> 
          DATA
          
          wd = UI;;WebDialog.new("WebDialog Bug with Alert on Windows",  true, nil, 300, 270, 600, 200, true) ; 
          
          result = wd.add_action_callback("setvalue") {|dialog, parm| 
          	value = nil ;
          	parm = [parm].pack('H*') 
          		
          	begin 
          		value = parm.to_l 
          	rescue 
          		UI.beep 
          		dialog.execute_script("alert('Invalid length >#{parm}<');")  
          	end  # begin  
          }
          	
          
          wd.set_html(myhtml) ; 
          wd.show 
          
          
          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            almost seems like a mis-placed quote, or at least something quote-related.

            Hi

            1 Reply Last reply Reply Quote 0
            • T Offline
              todd burch
              last edited by

              No indications of a syntax error anywhere. Only place (that would make sense) where the syntax error or misplaced quote might be would be in the ALERT function, but, even when I remove that and use a messagebox, I still get the error.

              It's almost as if the rescue is somehow changing the internal browser's stack to get confused in what should be displayed or something.

              1 Reply Last reply Reply Quote 0
              • J Offline
                Jim
                last edited by

                The example you posted displays the alert for me.

                UPdate - Ok, you already said this DOES work and the error is hard to reproduce.


                257.png

                Hi

                1 Reply Last reply Reply Quote 0
                • alexschreyerA Offline
                  alexschreyer Extension Creator
                  last edited by

                  I get this with normal websites when I forget the "return false" at the end of the onClick code so that the browser does not try to follow the link. Maybe try:

                  onclick="window.location='skp;setvalue@' + toHex(document.getElementById('ifield').value);return false"
                  

                  Cheers,
                  Alex

                  Author of "Architectural Design with SketchUp":
                  http://sketchupfordesign.com/

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    todd burch
                    last edited by

                    WOO-HOO!!!

                    That didn't fix it directly, but it did get me in the right area.

                    I first tried changing from a direct onclick="window.loc............" to calling a js function instead. I run the dialog, and enter junk:

                    VMware Fusion006.jpg

                    In the function, I did the callback, and after that, coded up a return false;, and this is what I got:

                    VMware Fusion007.jpg

                    So.... being the inquisitive guy I am... I removed the "false" from return false;. That did the trick!! Go figure.

                    I'm so HAPPY!! Thanks Alex.

                    1 Reply Last reply Reply Quote 0
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      @dan rathbun said:

                      therefore... you should be able to do it in the input tag thus:
                      onclick="void( window.location='skp:setvalue@' + toHex(document.getElementById('ifield').value) );"
                      .. and shouldn't need to have a function call.

                      ON second thot... chances are we'll forget and have the same 'bug' again on other projects.
                      Let's promote Jim Foltz's idea of using a generic callback function.

                      from Jim's v6 webconsole:
                      %(#8000BF)[

                      // Javascript
                          function cb(name, args) { // CALLBACK
                              window.location='skp;'+name+'@'+args;
                          }
                      
                      

                      ]
                      modified with a void operator and a bit of typechecking:
                      %(#8000BF)[

                      // Javascript
                          function cb(name, args) { // CALLBACK
                            if typeof(name)=='string' {
                              if typeof(args)!='string' { args=args.toString }
                              void( window.location='skp;'+name+'@'+args; ); 
                            }
                            else {
                              void( window.location='skp;webError@Callback name is not a string!';);
                            }
                          }
                      
                      

                      ]
                      So, Todd's callback could be:
                      onclick="cb( 'setvalue',toHex(document.getElementById('ifield').value) );"

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        @unknownuser said:

                        So.... being the inquisitive guy I am... I removed the "false" from return false;. That did the trick!! Go figure.

                        return [( [expression] [)];]

                        @unknownuser said:

                        "If expression is omitted, or no return statement is executed from within the function, the expression that called the current function is assigned the value undefined."
                        http://msdn.microsoft.com/en-us/library/22a685h9(VS.85).aspx

                        void expression

                        @unknownuser said:

                        "The void operator evaluates its expression, and returns undefined. It is most useful in situations where you want an expression evaluated but do not want the results visible to the remainder of the script.
                        The expressionargument is any valid JScript expression."
                        http://msdn.microsoft.com/en-us/library/e17c7cbe(VS.85).aspx

                        .. this is why you often see void(0); used in the HREF attribute for controls (such as a <A> tag,) that display popups or alert boxes.
                        ADDED: See SCF topic: [url=http://forums.sketchucation.com/viewtopic.php?f=180&t=25252:dqe1rmdx]Webdialogs and Javascript void[/url:dqe1rmdx]

                        therefore... you should be able to do it in the input tag thus:
                        onclick="void( window.location='skp:setvalue@' + toHex(document.getElementById('ifield').value) );"
                        .. and shouldn't need to have a function call.

                        EDIT: put MSDN quotes in quoteboxes for clarity.

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement