Welcome to the new Sahi Forums!
check if a checkbox is checked..but checkbox is _input element
  • Hello,
    I have a checkbox that is given like this:

    <input type="button" hidefocus="true" autocomplete="off" class="x-form-field x-form-checkbox" id="ext-gen1531" aria-checked="true" aria-invalid="false" data-errorqtip="" role="checkbox" aria-describedby="imagecheckbox-1369-errorEl" style="-moz-user-select: text;">

    How can I check if it is checked or not?

    Thank you!!!
  • 9 Comments sorted by
  • Hi Gligo
    I hope this helps.
    Use something like..
    _set($currentState, $myInput.getAttribute("aria-checked"));
    ... to assign the state of the checkbox to a variable.
    I think in your case $myinput would be _button(0)

    Im working with extjs checkboxes using...

    If you set $value to true ("True" or "true") the checkbox will be checked or remain checked. If $value is set to false ("False" or "false") the check box will be unchecked or remain unchecked.

    function _selectCheckBoxValueByLabel($checkBoxLabel, $value){
    var $checked;
    //string into boolean
    if ($value === "True" || $value === "true" || $value === true){
    $checked = true ;
    }
    if ($value === "False" || $value === "false" || $value === false) {
    $checked = false ;
    }
    if ($checked === true || $checked === false){
    var $myObject = _div(3, _near(_label($checkBoxLabel)));
    var $myInput = _button (0, _in($myObject));
    var $currentState;
    _set($currentState, $myInput.getAttribute("aria-checked"));
    var $checkedBoolean = false ;
    if($currentState === "true"){
    $checkedBoolean = true ;
    }
    if ($checked !== $checkedBoolean){
    _click ($myInput);
    }
    } else {
    _log ("Invalid $value in function _selectCheckBoxValueByLabel", "error");
    }
    }
  • Can't anyone help me?
  • Hi gligo,

    Seeing your code it seems that its an extjs checkbox and not the normal checkbox.

    Here is an example:
    _navigateTo("http://dev.sencha.com/deploy/ext-4.0.0/examples/form/dynamic.html";);
    <browser>
    function isSelected($button){
        if($button.className.indexOf("x-form-cb-focus") != -1){
            return false;
        }
        else {
            return true;
        }
    }
    </browser>
    
    //At start the button is not selected
    _click(_button(0));
    _assertTrue(isSelected(_button(0)));
    _click(_button(0));
    _assertFalse(isSelected(_button(0)));
    _click(_button(0));
    _assertTrue(isSelected(_button(0)));
    

    Let me know if you face any problem.

    Regards
    Sumitra
  • I want to write a code like this:
    if ($value=="1") {
    if (_condition(!isSelected(_button(0)))) {
    _click(_button(0));
    }
    }
    else if ($value=="0") {
    if (_condition(isSelected(_button(0)))) {
    _click(_button(0));
    }
    }

    But somehow the first case, which proves if the checkbox is unchecked, does not work..
  • Ok, I think this function will not work by me, because I always have this "x-form-cb-focus" no matter of the state. the only thing that is changing is aria-checked="true" , when it is unchecked, it is changed to "false"....can you help me once again?
  • Hi ,
    I am exactly into the same issue trying to check a extjs checkbox of the input type "button". The issue here is that the button class name or any property of that element does not change if checked or unchecked. The only thing that changes is the Table classname for that checkbox now how can i get the table classname for the button which is in the <td>?

    here is the table only table class changes when we check or uncheck the checkbox

    class="x-field x-form-item x-field-default x-checkboxgroup-form-item x-form-dirty"


    <table id="checkboxfield-1018" class="x-field x-form-item x-field-default x-checkboxgroup-form-item x-form-dirty" cellpadding="0" style="table-layout: auto;">
    <tbody>
    <tr id="checkboxfield-1018-inputRow">
    <td id="checkboxfield-1018-labelCell" class="x-field-label-cell" width="105" valign="top" halign="left" style="display:none;">
    <td id="checkboxfield-1018-bodyEl" class="x-form-item-body x-form-cb-wrap" role="presentation" colspan="3">
    <input id="checkboxfield-1018-inputEl" class="x-form-field x-form-checkbox" type="button" hidefocus="true" autocomplete="off" aria-invalid="false" data-errorqtip="" style="-moz-user-select: text;">
    <label id="checkboxfield-1018-boxLabelEl" class="x-form-cb-label x-form-cb-label-after" for="checkboxfield-1018-inputEl">DA Discrete Input/Output</label>
    </td>
    </tr>
    </tbody>
    </table

    Any help is highly appreciated.
  • This was a hard one but finally got it, spent almost the whole day to get this working. It is pretty difficult with sencha because our checkbox's are rendered as buttons and no property of buttons change if it is checked or unchecked. So by taking the label as the reference I truncated the element ID and used it to get the table classname (which changes when checked or unchecked) . Using that I verified if it is checked or not.

    But the AssertTrue does not work for the function return (true/false)
  • Can you show the code how you solved the problem, please?
  • function isSelected($labelName) {
    var $Cname;
    //var $CnameAftr;
    var $butID;

    // Constant class name for the checked object
    var $val = "x-field x-form-item x-field-default x-checkboxgroup-form-item x-form-cb-checked";
    _set($butID, _button(0, _near(_label($labelName))).id);
    //_alert($butID);

    var $trunc = $butID.substring(0, $butID.length - 8);
    //_alert($trunc);

    _set($Cname, _table($trunc).className);


    if($Cname != $val) {

    //return false;
    _log("Not Checked");
    }
    else {
    //return true;
    _log("Checked");
    }

    }


    isSelected('label');
    _click(_button(0, _near(_label("label"))));
    isSelected('label');


    I hard coded it value since our app has very few checkboxes the right way is to use regular expression something like this

    var $val = "/.*cb-checked.*/";

    Hope this helps!!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter