Set Check-box from button click

rss

Posted by Hubbaroo - Sep 11 ’15 at 06:30

When I ckick the check-box the change function works. When I set the value from a button on-click the check-box changes but the change event does not fire? Maybe I'm doing it wrong?

 

Thanks

  • rostislav
    rostislav
    Moderator
    Member for: 6 years 8 months 17 days
    #1 by rostislav Sep 14 ’15 at 03:53

    Instead of using fd.field(...).value(), use:

    fd.field('checkbox').control()._el().find('tr input').eq(1).click()
    

    Where 'checkbox' is the internal name of the checkbox control and 1 in eq(1) is the index of the checkbox in the checkbox control that you want to select/unselect. click() is effectively the same as clicking the checkbox with your mouse.

  • Hubbaroo
    Member
    Member for: 8 years 4 months 2 days
    #2 by Hubbaroo Sep 18 ’15 at 12:33

    This is what I have in the button on click:

    fd.field('DTProjectNumberRequested').value('1');
    fd.field('DTProjectNumberRequested').control()._el().find('tr input').eq(1).click();
    alert('Hello');

    The checkbox gets checked, the checkbox's on click event does not fire, the alert does pop up. Thanks again, it's the easy things sometimes.

     

    Hubbaroo

  • rostislav
    rostislav
    Moderator
    Member for: 6 years 8 months 17 days
    #3 by rostislav Sep 22 ’15 at 04:46

    [#2]:

    Having this code in the JS editor:

    fd.field('DTProjectNumberRequested').change(function(){
     alert('clicked');
     });
    

    And this code in the button onclick handler:

    fd.field('DTProjectNumberRequested').control()._el().find('tr input').eq(1).click();
    

    Works. I have just tested it on my machine. If it doesn't work for you: -check the InternalName is correct (it's not nesessarily the same as the caption for your checkbox control. check it under 'InternalName' in the property grid in Forms Designer for you control) -check console for any JS errros. If you get exceptions in your code it may stop your handler from attaching for example (F12 -> console to bring up the console, depending on the browser). -if the problem still persists, send us the html of your page to [email protected]

  • Hubbaroo
    Member
    Member for: 8 years 4 months 2 days
    #4 by Hubbaroo Sep 22 ’15 at 12:33

    I sent the file after following your instructions.

  • rostislav
    rostislav
    Moderator
    Member for: 6 years 8 months 17 days
    #5 by rostislav Sep 23 ’15 at 04:38

    [#4]:

    Please use the following code:

    fd.field('DTProjectNumberRequested').control()._el().find('span input').eq(0).click();
    

    (I assumed you were using a multiple checkbox control, not boolean).

Displaying 1 to 5 of 5 messages