Facility Control

 View Only
  • 1.  radio button state

    Posted 10-05-2018 15:03
    Hi,

    I have a radio button in my dasboard and I try to get the state.
    params.getValue('myBtn',0); doesn't work.

    How can I proceed please ?

    Thanks


  • 2.  RE: radio button state

    Posted 10-05-2018 15:36

    here is the code of the button:

    <button buttontype="radio" height="186" id="radioX" left="630" name="RADIO X" top="81" width="259">
    <task tasktype="ogscript">ogscript.debug(params.getValue ('radioX',0));</task>
    </button>

    Thanks


    #DashBoard


  • 3.  RE: radio button state

    Posted 10-05-2018 19:06

    Anything requiring state needs a parameter created for it. A is different from a <button/>.

    <abs contexttype="opengear" gridsize="20" id="_top">
       <meta>
          <params>
             <param access="1" constrainttype="INT_CHOICE" name="radioX" oid="radioX" precision="0" type="INT32" value="0" widget="radio-vertical">
                <constraint key="0">Off</constraint>
                <constraint key="1">On</constraint>
             </param>
          </params>
       </meta>
       <param expand="true" height="60" left="60" oid="radioX" top="60" width="260">
          <task tasktype="ogscript">ogscript.debug(params.getValue ('radioX',0));</task>
       </param>
    </abs>
    

    #DashBoard


  • 4.  RE: radio button state

    Posted 10-08-2018 11:13
    Hi James,
    thanks for your feedback.

    This is not exactly what I want to do.
    I want to use a button with a radio type. And I need to detect is state when it is on toggle ON or on toggle OFF.
    My solution for the moment is to create a variable and put a condition script on the task of the button. It makes the job but I thought there was a native solution script.

    Thanks ;)

    #DashBoard


  • 5.  RE: radio button state

    Posted 10-08-2018 13:01

    Well, technically what James told you is exactly what you want to do. But I do understand your frustration/confusion as I've had this issue before as well...

    When creating a button, you can create it as a simple button, a toogle, a checkbox, or indeed a radio button.
    However, these buttons are "dumb" and, as far as I know, there is no way to read what "state" they are in.
    So as I've mentioned before, I would suggest that these options would be removed when creating a simple button...

    Now, to your question...

    1: Creating a radio-button to detect on/off state is not what the radio buttons were designed for when they first appeared in any shape or form.
    A radio button is used when you want the user to be able to chose 1 of several options, but only 1 of those options.
    What you're essentially looking for is a boolean (a true or false). For this, we have the checkbox.

    2: To create a checkbox in DashBoard where you can read the state of the button when clicked, you have to create parameter to hold this value.
    When you have created the parameter that shows up as a checkbox, you can add a task to this "parameter-button", that when clicked will run this task.

    (Having it in a parameter also means you can check this value when other tasks are run)

    Now, in the task, you have to get the value of self (or the parameter OID if you want), and do a single if/else check on it.
    I've attached a working example below that updates a parameter when clicked.

    <abs contexttype="opengear" gridsize="20" id="_top">
       <meta>
          <params>
             <param access="1" constrainttype="INT_CHOICE" name="checkbox" oid="checkbox" precision="0" type="INT32" value="0" widget="checkbox">
                <constraint key="0">Off</constraint>
                <constraint key="1">On</constraint>
             </param>
             <param access="1" maxlength="0" name="text" oid="text" type="STRING" value="Checkbox is: UNCHECKED!" widget="label"/>
          </params>
       </meta>
       <param expand="true" height="40" left="260" oid="checkbox" top="160" width="60">
          <task tasktype="ogscript">var x = params.getValue('checkbox', 0); // We get the current value of the checkbox parameter and set as variable X
    
    if (x == 1) { // We check to see if the checkbox is checked.
       params.setValue('text', 0, 'Checkbox is: CHECKED!'); // If checked, we change the parameter/label text to reflect that it is indeed checked.
    } else {
       params.setValue('text', 0, 'Checkbox is: UNCHECKED!'); // if it's NOT checked, we change the text to reflect that it's not checked.
    }</task>
       </param>
       <param expand="true" height="40" left="320" oid="text" style="size:Big;" top="160" width="260"/>
    </abs>

    If you want I can give you an example of how to use the radio buttons as well? However this will be more than 1 button. As that is just the nature of the radio button.


    #DashBoard


  • 6.  RE: radio button state

    Posted 10-11-2018 13:37
    Hi astalsberg, thank you for your solution.

    #DashBoard