jQWidgets Forums

This topic contains 1 reply, has 2 voices, and was last updated by  Nadezhda 10 years, 3 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Radiobutton group cancel event #65219

    Peter Sloth
    Participant

    Hi

    I have a radiobutton group and based on some conditions the user should not be allowed to change the value for a radiobutton in the group.
    So how do I cancel the event in demo sample code below?

    thanks

    Peter Sloth

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta name="keywords" content="jQuery Button, CheckBox, Toggle Button, Repeat Button, Radio Button, Link Button, Button" />
        <meta name="description" content="With the jqxRadioButton, users make a choice among a set of mutually exclusive, related options. Users can choose one and only one option." />
        <title id='Description'>With the jqxRadioButton, users make a choice among a set of
            mutually exclusive, related options. Users can choose one and only one option.
        </title>
        <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
        <script type="text/javascript" src="../../scripts/demos.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxradiobutton.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {   
                $("#jqxRadioButton").jqxRadioButton({ width: 250, height: 25, checked: true});
                $("#jqxRadioButton2").jqxRadioButton({ width: 250, height: 25});
                $("#jqxRadioButton3").jqxRadioButton({ width: 250, height: 25});
                $("#jqxRadioButton4").jqxRadioButton({ width: 250, height: 25, disabled: true});
                   
                var clearLog = function () {
                    var log = $('#events').find('span');
                    if (log.length >= 2) {
                        log.remove();
                    }
                }
    
                $("#jqxRadioButton").on('change', function (event) {
                    clearLog();
                    var checked = event.args.checked;
                    if (checked) {
                        $("#events").prepend('<div><span>Checked: 12 Months Contract</span></div>');
                    }
                    else $("#events").prepend('<div><span>Unchecked: 12 Months Contract</span></div>');
                });
                $("#jqxRadioButton2").on('change', function (event) {
                    // how to cancel this event?
                    clearLog();
                    var checked = event.args.checked;
                    if (checked) {
                        $("#events").prepend('<div><span>Checked: 6 Months Contract</span></div>');
                    }
                    else $("#events").prepend('<div><span>Unchecked: 6 Months Contract</span></div>');
                });
                $("#jqxRadioButton3").on('change', function (event) {
                    clearLog();
                    var checked = event.args.checked;
                    if (checked) {
                        $("#events").prepend('<div><span>Checked: 3 Months Contract</span></div>');
                    }
                    else $("#events").prepend('<div><span>Unchecked: 3 Months Contract</span></div>');
                });
            });
        </script>
    </head>
    <body class='default'>
        <div id='jqxWidget' style='font-family: Verdana Arial; font-size: 12px; width: 400px;'>
            <h3>
                House Contract</h3>
            <div style='margin-top: 10px;' id='jqxRadioButton'>
                12 Months Contract</div>
            <div style='margin-top: 10px;' id='jqxRadioButton2'>
                <span>6 Months Contract</span></div>
            <div style='margin-top: 10px;' id='jqxRadioButton3'>
                <span>3 Months Contract</span></div>
            <div style='margin-top: 10px;' id='jqxRadioButton4'>
                <span>1 Month Contract</span></div>
            <div style='margin-top: 10px;'>
                <div>
                Events:
                </div>
                <div id='events'>
                </div>
            </div>
        </div>
    </body>
    </html>
    
    Radiobutton group cancel event #65259

    Nadezhda
    Participant

    Hello Peter Sloth,

    Here is an example from RadioButton Demo and event.stopPropagation(); which preventing any parent handlers from being notified of the event.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title></title>
        <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
        <script type="text/javascript" src="../../scripts/demos.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxradiobutton.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {   
                $("#jqxRadioButton").jqxRadioButton({ width: 250, height: 25, checked: true});
                $("#jqxRadioButton2").jqxRadioButton({ width: 250, height: 25});
                $("#jqxRadioButton3").jqxRadioButton({ width: 250, height: 25});
                $("#jqxRadioButton4").jqxRadioButton({ width: 250, height: 25, disabled: true});               
                var clearLog = function () {
                    event.stopPropagation();
                    var log = $('#events').find('span');
                    if (log.length >= 2) {
                        log.remove();
                    }
                }
    
                $("#jqxRadioButton").on('change', function (event) {
                    clearLog();
                    var checked = event.args.checked;
                    if (checked) {
                        $("#events").prepend('<div><span>Checked: 12 Months Contract</span></div>');
                    }
                    else $("#events").prepend('<div><span>Unchecked: 12 Months Contract</span></div>');
                });
                $("#jqxRadioButton2").on('change', function (event) {
                    clearLog();
                    var checked = event.args.checked;
                    if (checked) {
                        $("#events").prepend('<div><span>Checked: 6 Months Contract</span></div>');
                    }
                    else $("#events").prepend('<div><span>Unchecked: 6 Months Contract</span></div>');
                });
                $("#jqxRadioButton3").on('change', function (event) {
                    clearLog();
                    var checked = event.args.checked;
                    if (checked) {
                        $("#events").prepend('<div><span>Checked: 3 Months Contract</span></div>');
                    }
                    else $("#events").prepend('<div><span>Unchecked: 3 Months Contract</span></div>');
                });
            });
        </script>
    </head>
    <body class='default'>
        <div id='jqxWidget' style='font-family: Verdana Arial; font-size: 12px; width: 400px;'>
            <h3>
                House Contract</h3>
            <div style='margin-top: 10px;' id='jqxRadioButton'>
                12 Months Contract</div>
            <div style='margin-top: 10px;' id='jqxRadioButton2'>
                <span>6 Months Contract</span></div>
            <div style='margin-top: 10px;' id='jqxRadioButton3'>
                <span>3 Months Contract</span></div>
            <div style='margin-top: 10px;' id='jqxRadioButton4'>
                <span>1 Month Contract</span></div>
            <div style='margin-top: 10px;'>
                <div>
                Events:
                </div>
                <div id='events'>
                </div>
            </div>
        </div>
    </body>
    </html>

    Best Regards,
    Nadezhda

    jQWidgets team
    http://www.jqwidgets.com/

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.