Is there a .change event for checkboxlist?

(10 posts) (2 voices)
  1. cris, Member

    I have a checkbox list as a connected parameter. I want to color red some of the checkbox labels if the word 'Caution' appears in the label text. I can do this:


    if ($('label[for="addNewRecord_u9_1_cbl"]').is(':contains("Caution")')) {
    $('label[for="addNewRecord_u9_1_cbl"]').css('color', 'red');
    }
    else {
    $('label[for="addNewRecord_u9_1_cbl"]').css('color', 'green');
    }

    However, this only works for the initial loading of the checkbox list. If previous selections change the content of the checkbox list, the color does not change. I tried using the .change event for the checkbox list, but it doesn't seem to work?


    $('#addNewRecord_u9_1_cbl').change(function(){ if ($('label[for="addNewRecord_u9_1_cbl"]').is(':contains("Caution")')) {
    $('label[for="addNewRecord_u9_1_cbl"]').css('color', 'red');
    }
    else {
    $('label[for="addNewRecord_u9_1_cbl"]').css('color', 'green');
    } });

    I also tried just $('#addNewRecord_u9').change with no effect. Am I putting the .change on the wrong selector?

    Thanks,
    Cris

  2. myDBR Team, Key Master

    Cris,
    the change event will not work as the whole parameter is refetched via Ajax when the change on parent parameters happen.

    What you can do is to update to the latest version which allows use of dbr.html with connected parameter labels. You can use:

    select id, concat( 'dbr.html:<span style="color:', if (label like '%Caution%', 'red', 'green')  ,'">', label, '</span>')
    from param
    where ...

    When using this, there is no need for JavaScript and both initial load and subsequent Ajax loads work alike.

    --
    myDBR Team

  3. cris, Member

    Awesome. Works perfectly. Thank you.

  4. cris, Member

    Would it be possible / easy to extend the use of dbr.html in connected parameter select lists also? I am trying to do something very similar to the above example, but with a select list this time instead of a checkbox list.

    Thank you,
    Cris

  5. myDBR Team, Key Master

    Cris,
    individual choises in native SELECT-elements are OPTIONs. HTML standard (or browsers) do not allow other than text inside the OPTION.

    It could be possible to use HTML when myDBR's "select list + find" would be used where the native SELECT is replaced with a JavaScript version. We can take a look if it would be easy to allow HTML in it.

    --
    myDBR Team

  6. cris, Member

    Whoa, I never noticed the "select list + find" option before. That is cool and useful. It will work out nicely if I could use HTML in that control.

    Thanks!
    Cris

  7. myDBR Team, Key Master

    The latest build allows for you to use 'dbr.htm:'-syntax with "select list + find". This allows for you to use things like colors etc in the select list.

    --
    myDBR Team

  8. cris, Member

    Thank you. This works on the initial load of the report, but loses the ability to display the HTML as soon as a parent connected parameter above is changed.

  9. myDBR Team, Key Master

    In order it to work in connected parameters, a bit more work was needed. You can now run the updater and also the connected parameter use case is covered.

    --
    myDBR Team

  10. cris, Member

    Works great! Thank you very much for the extra effort. I'm still amazed I didn't know the 'select list + find' was there. It's neat to use a product for 4 years and still discover valuable features.


Reply

You must log in to post.