jQuery UI Widgets Forums Plugins Validator, Drag & Drop, Sortable Conditional Validation

This topic contains 2 replies, has 2 voices, and was last updated by  ToddHaddaway 8 years, 8 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • Conditional Validation #50703

    ToddHaddaway
    Participant

    Is there a way to require a field only if a checkbox is checked?

    I currently have a checkbox defined:
    $(“#checkboxA”).jqxCheckBox({ width: 120, height: 25 });

    And I have validation on a field:

    $('#initalPageForm').jqxValidator({
        rules: [
                 { input: '#myDropdown', message: 'You must select a section', action: 'change', rule: function () {
    		var selectedIndexSection = $('#myDropdown').jqxDropDownList('selectedIndex');
    		var result = selectedIndexSection > 0;
    		return result;}
    	      }                           
    	    ]	                    
    	            });
    

    I would like to require myDropDown be selected ONLY if checkBoxA is checked. myDropDown is optional if checkBoxA is NOT checked.

    Thanks!

    Conditional Validation #50747

    Dimitar
    Participant

    Hello ToddHaddaway,

    If the checkbox is checked, the rule should return the calculated result and if not – true:

    $('#initalPageForm').jqxValidator({
        rules: [
                    { input: '#myDropdown', message: 'You must select a section', action: 'change', rule: function () {
                        var selectedIndexSection = $('#myDropdown').jqxDropDownList('selectedIndex');
                        var result = selectedIndexSection > 0;
                        if ($("#checkboxA").val() == true) {
                            return result;
                        } else {
                            return true;
                        };
                    }
                    }
    	        ]
    });

    Best Regards,
    Dimitar

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

    Conditional Validation #50775

    ToddHaddaway
    Participant

    Thank you!

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

You must be logged in to reply to this topic.