Announcement

Collapse
No announcement yet.

jqButton with AddScript()

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • jqButton with AddScript()

    Since we still cant search this forum, I'll post the question here - not sure if it has been covered...

    I have a jqButton defined and am trying to call a script for the onClick:
    PHP Code:
    Dim b As New clsJQuery.jqButton("btnTestConnection""Test Connection"IFACE_NAMEFalse)
            
    b.AddScript("function userConfirm() {  confirm(""hey - are you sure??"");  }")
            
    b.functionToCallOnClick "userConfirm()"
            
    sbtb.Append(b.Build
    When it builds the page, I see in the source view that the function is built, but the button does not have an onClick property and the script never gets called. For that matter, I do not see the confirm("hey are you sure??") in there either...
    PHP Code:
    <script>
    $(function() {
    $(
    '#btnTestConnection_ID598385').button({icons: {primary:'',secondary:''} });
    $(
    '#btnTestConnection_ID598385').click(function() {
    userConfirm()
    var 
    theData='';
    returnTrue false
    theData 
    theData+'&id='+this.id+'&btnTestConnection=Submit';
    commonAjaxPost(theData,'My Plugin');
    if(
    returnTrue) {
    location.reload();
     return 
    false;
    }
    else {
     return 
    false;
    }
    });
    });
    </
    script>
    <
    button type='submit'   id='btnTestConnection_ID598385'  name='btnTestConnection' >Test Connection</button
    So, how should we use AddScript to have a jqButton call a script?
    HS3Pro Running on a Raspberry Pi3
    64 Z-Wave Nodes, 168 Events, 280 Devices
    UPB modules via OMNI plugin/panel
    Plugins: Z-Wave, BLRF, OMNI, HSTouch, weatherXML, EasyTrigger
    HSTouch Clients: 3 Android, 1 Joggler

  • #2
    It looks like you need to set the includeClickFunction to true as well.
    Wade

    sigpic

    website | products | support | youtube
    I know nothing...., nothing!!!

    Comment


    • #3
      I added that property and the generated code still is not bringing over my function from the AddScript:
      PHP Code:
      Dim b As New clsJQuery.jqButton("btnTestConnection""Test Connection"IFACE_NAMEFalse)
              
      b.AddScript("function userConfirm() {  confirm(""hey - are you sure??"");  }")
              
      b.functionToCallOnClick "userConfirm()"
              
      b.includeClickFunction True
              sbtb
      .Append(b.Build

      When I do a view/source, this is the script area for the button:
      PHP Code:
      <script>
      $(function() {
      $(
      '#btnTestConnection_ID598385').button({icons: {primary:'',secondary:''} });
      $(
      '#btnTestConnection_ID598385').click(function() {
      userConfirm()
      var 
      theData='';
      returnTrue false
      theData 
      theData+'&id='+this.id+'&btnTestConnection=Submit';
      commonAjaxPost(theData,'MyPlugin');
      if(
      returnTrue) {
      location.reload();
       return 
      false;
      }
      else {
       return 
      false;
      }
      });
      });
      </
      script>
      <
      button type='submit'   id='btnTestConnection_ID598385'  name='btnTestConnection' >Test Connection</button
      It looks to be the same as before - no effect on includeClickFunction=True

      Am I right in thinking that this is how AddScript works with the jqButton?
      HS3Pro Running on a Raspberry Pi3
      64 Z-Wave Nodes, 168 Events, 280 Devices
      UPB modules via OMNI plugin/panel
      Plugins: Z-Wave, BLRF, OMNI, HSTouch, weatherXML, EasyTrigger
      HSTouch Clients: 3 Android, 1 Joggler

      Comment


      • #4
        you could add this as a string after adding button build.

        addscript isnt documented, is it like you see it or is it a reference to a script file.


        PHP Code:
        <script type='text/javascript'userConfirm() {  confirm(""hey are you sure??"");  }</script

        Comment


        • #5
          Originally posted by wetlip View Post
          you could add this as a string after adding button build.

          addscript isnt documented, is it like you see it or is it a reference to a script file.


          PHP Code:
          <script type='text/javascript'userConfirm() {  confirm(""hey are you sure??"");  }</script
          Yes, that adds the script code, but it never gets called. I think if it somehow does get called, the post/postback will still occur regardless if you press ok or cancel.

          I dont believe AddScript references a file - my assumption is that it allows you to do some inline js for jquery. Since it's not documented, that is a big assumption

          HST - we really would like some way to prompt the user with "Are you sure?" for jqButton.
          HS3Pro Running on a Raspberry Pi3
          64 Z-Wave Nodes, 168 Events, 280 Devices
          UPB modules via OMNI plugin/panel
          Plugins: Z-Wave, BLRF, OMNI, HSTouch, weatherXML, EasyTrigger
          HSTouch Clients: 3 Android, 1 Joggler

          Comment


          • #6
            The problem is the script variable is being cleaned just prior to building the object.

            Adding your script to the top of your page should fix this.
            Wade

            sigpic

            website | products | support | youtube
            I know nothing...., nothing!!!

            Comment


            • #7
              Excellent - thanks Wade!
              HS3Pro Running on a Raspberry Pi3
              64 Z-Wave Nodes, 168 Events, 280 Devices
              UPB modules via OMNI plugin/panel
              Plugins: Z-Wave, BLRF, OMNI, HSTouch, weatherXML, EasyTrigger
              HSTouch Clients: 3 Android, 1 Joggler

              Comment


              • #8
                Did you guys finally got this confirmation box/function to work?
                Thanks for sharing
                Dirk

                Comment


                • #9
                  Almost 7 years after and I have the same problem. How to implement a "Are you sure dialog". Does anyone have a some code to show me?

                  Comment


                  • #10
                    I made my own solution

                    https://forums.homeseer.com/forum/de...77#post1354977

                    Comment

                    Working...
                    X