• Login
sketchucation logo sketchucation
  • Login
🤑 30% Off | Artisan 2 on sale until April 30th Buy Now

Executing one call_back executes another.

Scheduled Pinned Locked Moved Developers' Forum
12 Posts 6 Posters 589 Views
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.
  • S Offline
    sdmitch
    last edited by 31 May 2015, 00:26

    I have been working on a WebDialog for a plugin that selects entities using attributes. In debugging the code, I was surprised to see the two call_backs, one that loads the form and one do the selection, were both being executed when the select button was clicked.
    select by attribute.gif

    			@dlg.add_action_callback("InitializeForm") { 
    				
    					self.get_attributes;puts "Initializing Form"
    					@dlg.execute_script("clearList('dic');");@dlg.execute_script("addToList('dic',#{@dict_names});");
    					@dlg.execute_script("clearList('key');");@dlg.execute_script("addToList('key',#{@dict_keys});");
    					@dlg.execute_script("clearList('val');");@dlg.execute_script("addToList('val',#{@key_values});");
    					
    			};
    
    			@dlg.add_action_callback("ValueChanged") {|d,p|
    				var,val=p.strip.split("="); puts p
    				case var
    					when 'dic' then @name=val
    					when 'key' then @key=val
    					when 'val' then @value=val
    					when 'btn' then select_by_attribute
    				end
    			};
    
    

    Anyone ever experienced this before?

    Nothing is worthless, it can always be used as a bad example.

    http://sdmitch.blogspot.com/

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 31 May 2015, 12:05

      We don't see you js or html... or most of your rb.
      So when is the callback "InitializeForm" called ?
      If it is called as the html is ready then if you reload the page after the "Select" button is clicked then that callback does re-run ?
      The values do default so I suspect something is reloading the page's html ?

      TIG

      1 Reply Last reply Reply Quote 0
      • S Offline
        sdmitch
        last edited by 31 May 2015, 16:13

        @tig said:

        We don't see you js or html... or most of your rb.
        So when is the callback "InitializeForm" called ?
        If it is called as the html is ready then if you reload the page after the "Select" button is clicked then that callback does re-run ?
        The values do default so I suspect something is reloading the page's html ?

        "initializeForm" is called when the html is loaded but I am not knowingly doing anything that would cause the html to reload when the select button is clicked.


        Select by Attribute_WD.rb

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • D Offline
          driven
          last edited by 31 May 2015, 16:31

          have you got a link for the model?

          It has no values for the models I've tried, and it would be easier if we look at the same one...

          if you remove value="select" from the button attributes does it work correctly?

          john

          learn from the mistakes of others, you may not live long enough to make them all yourself...

          1 Reply Last reply Reply Quote 0
          • S Offline
            sdmitch
            last edited by 31 May 2015, 16:53

            @driven said:

            have you got a link for the model?

            It has no values for the models I've tried, and it would be easier if we look at the same one...

            if you remove value="select" from the button attributes does it work correctly?

            john

            No change with value="select" removed.

            Here is the model provided to me that I have been testing with.


            scaffold with attributes_v14.skp

            Nothing is worthless, it can always be used as a bad example.

            http://sdmitch.blogspot.com/

            1 Reply Last reply Reply Quote 0
            • T Offline
              TIG Moderator
              last edited by 31 May 2015, 17:04

              In HTML the <script> code block normally goes in the <header>, NOT the <body> - try moving it into there and retest...

              As it is window.location='skp:InitializeForm@'; is run whenever the HTML body loads.
              Currently your code makes a new WebDialog for @dlg afresh every time your tool is run, perhaps adding unless @dlg after it would at least prevent that ?

              TIG

              1 Reply Last reply Reply Quote 0
              • S Offline
                sdmitch
                last edited by 31 May 2015, 17:24

                @tig said:

                In HTML the <script> code block normally goes in the <header>, NOT the <body> - try moving it into there and retest...

                As it is window.location='skp:InitializeForm@'; is run whenever the HTML body loads.
                Currently your code makes a new WebDialog for @dlg afresh every time your tool is run, perhaps adding unless @dlg after it would at least prevent that ?

                Moving script to the header only caused the select list to remain empty. Adding the unless caused the InitializeForm to not run at all.

                Why InitializeForm is run every time a button is clicked is still a mystery for now. I have managed to overcome the problems that caused.

                Nothing is worthless, it can always be used as a bad example.

                http://sdmitch.blogspot.com/

                1 Reply Last reply Reply Quote 0
                • M Offline
                  MSP_Greg
                  last edited by 1 Jun 2015, 01:51

                  @sdmitch said:

                  "initializeForm" is called when the html is loaded but I am not knowingly doing anything that would cause the html to reload when the select button is clicked.

                  Remove the form tags. Forms have some odd default behavior, in this case, reloading the html...

                  Attached an rb file with some changes --

                  1. Uses 'html is loaded' for callback
                  2. Changed 'InitializeForm' execute_script statements to pass arrays

                  I did remove the top of the code.

                  Greg


                  Select by Attribute_WD 1.1.rb

                  1 Reply Last reply Reply Quote 0
                  • S Offline
                    sdmitch
                    last edited by 1 Jun 2015, 13:55

                    @msp_greg said:

                    @sdmitch said:

                    "initializeForm" is called when the html is loaded but I am not knowingly doing anything that would cause the html to reload when the select button is clicked.

                    Remove the form tags. Forms have some odd default behavior, in this case, reloading the html...

                    Attached an rb file with some changes --

                    1. Uses 'html is loaded' for callback
                    2. Changed 'InitializeForm' execute_script statements to pass arrays

                    I did remove the top of the code.

                    Greg

                    Greg, Thanks for help. It seems that the form tags were the majority of the problem.

                    Nothing is worthless, it can always be used as a bad example.

                    http://sdmitch.blogspot.com/

                    1 Reply Last reply Reply Quote 0
                    • tt_suT Offline
                      tt_su
                      last edited by 3 Jun 2015, 14:25

                      Did you make that buttom a Submit button? By default I think that will make a POST request to the same page it is on. You need to either capture that event and prevent the default action, or make the button a non-submit: <input type="button"> or <button></button>.

                      1 Reply Last reply Reply Quote 0
                      • S Offline
                        sdmitch
                        last edited by 3 Jun 2015, 15:58

                        @tt_su said:

                        Did you make that buttom a Submit button? By default I think that will make a POST request to the same page it is on. You need to either capture that event and prevent the default action, or make the button a non-submit: <input type="button"> or <button></button>.

                        No, I just removed the <form></form> and that fixed the "problem".

                        Nothing is worthless, it can always be used as a bad example.

                        http://sdmitch.blogspot.com/

                        1 Reply Last reply Reply Quote 0
                        • thomthomT Offline
                          thomthom
                          last edited by 3 Jun 2015, 17:11

                          That would do the same thing - the <form> element usually have the URL to which to submit to. Without a parent <form> the submit button had no default action.

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

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

                          Advertisement