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

    Get_element_value issue (on Mac)

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 4 Posters 2.3k Views 4 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.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by

      If that does not work.. it is likely an sync issue. The Ruby statements continue to be executed and the one that closes the dialog executes before the value gets returned.

      Set up an javascript onChange event for the input, that fires a specific Ruby callback to set the projectName hash member.

      HTML

      <input size="20" form="Project" id="projectName"
       value="Nom du projet" type="text" onChange="project_name_to_ruby(this.value);">
      

      and JS:

      function project_name_to_ruby(proj) {
        window.location = "skp;set_project_name@" + proj;
      }
      

      And on the Ruby-side:

      @project_dialog.add_action_callback("set_project_name") { |d, p|
        @args["projectName"] = p.strip
      }
      

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • Didier BurD Offline
        Didier Bur
        last edited by

        Thanks Dan, I'll try that asap πŸŽ‰ and let you know which solution works...

        DB

        1 Reply Last reply Reply Quote 0
        • Didier BurD Offline
          Didier Bur
          last edited by

          Hi Dan,
          First option (using "id" instead of "name") does'nt work, so clearly this is a sync problem.
          Second option (js) works, but what a complex coding for such a simple task... Mac sucks πŸ‘Ž

          DB

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

            Syncing issue exists only when you send data from JavsScript to Ruby using the window.location = 'skp:......' protocol.

            get_element_value is synchronous.

            What triggers the "main_dlg_ok" callback? Is the HTML fully ready at that point?

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

            1 Reply Last reply Reply Quote 0
            • Didier BurD Offline
              Didier Bur
              last edited by

              Hi TT,

              @unknownuser said:

              What triggers the "main_dlg_ok" callback?

              It's a "OK" button:

              <input type ="button" value="Valider" onClick="window.location='skp;main_dlg_ok'">
              
              

              I don't exactly know if the HTML is ready at this point, because it is written "on demand", just after the user clicks on the icon that launches the WebDialog
              Regards,

              DB

              1 Reply Last reply Reply Quote 0
              • jolranJ Offline
                jolran
                last edited by

                A longshot.

                I noticed some difference in behaviors for button click events if assigning them inside the JS doc.ready functions instead of in the html tag.

                I'm using Jquery though..

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

                  I don't suppose to have a complete reproducible case?

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

                  1 Reply Last reply Reply Quote 0
                  • jolranJ Offline
                    jolran
                    last edited by

                    @unknownuser said:

                    I don't suppose to have a complete reproducible case?

                    Who me ?

                    No, I already sent you code to poke around for fouls πŸ˜‰

                    But you can just try putting onclick events in the html tag and see if you notice they missfire occasionally. (Compared to as having a function in the 'doc.ready' that binds the clickevent for the button that is.)

                    I dont not know why that happend for me. I just cared to mention it as a variable to test since I got the impression Didier was worried the html wasent ready.

                    1 Reply Last reply Reply Quote 0
                    • jolranJ Offline
                      jolran
                      last edited by

                      Ahh... Forget my suggestion.
                      Had a typo in the code that made the clickevent fail in a certain condition.

                      Thomthom probably knew that something fishy was going on.

                      So anyone have the solution to this syncing problem for Mac? I'm interested as well..

                      Didier. Did you make it work ?

                      1 Reply Last reply Reply Quote 0
                      • Didier BurD Offline
                        Didier Bur
                        last edited by

                        Hi,
                        I made it work the lazy way: data in the dialog box is saved in a global variable 😳 , so when the dialog closes it can be retrieved without js script or anything...

                        $args={}
                        @project_dialog.add_action_callback("main_dlg_ok") { |d, p|
                        			$args["nomProjet"] = d.get_element_value("nomProjet")
                                                $args["auteur"] = d.get_element_value("auteur")
                        ...
                        			@project_dialog.close			
                        }
                        

                        Thanks everybody for your help

                        DB

                        1 Reply Last reply Reply Quote 0
                        • jolranJ Offline
                          jolran
                          last edited by

                          That's one way of doing it. πŸ˜„

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

                            Surely an instance variable will work just as well? Avoiding the risk to collision of global variables - especially with a common variable name such as args.

                            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
                            • First post
                              Last post
                            Buy SketchPlus
                            Buy SUbD
                            Buy WrapR
                            Buy eBook
                            Buy Modelur
                            Buy Vertex Tools
                            Buy SketchCuisine
                            Buy FormFonts

                            Advertisement