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?
    HS4Pro on a Raspberry Pi4
    54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
    Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

    HSTouch Clients: 1 Android

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

    "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?
      HS4Pro on a Raspberry Pi4
      54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
      Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

      HSTouch Clients: 1 Android

      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.
          HS4Pro on a Raspberry Pi4
          54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
          Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

          HSTouch Clients: 1 Android

          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

            "I know nothing... nothing!"

            Comment


              #7
              Excellent - thanks Wade!
              HS4Pro on a Raspberry Pi4
              54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
              Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

              HSTouch Clients: 1 Android

              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