tonydspaniard / Yii-extensions

My small contribution to the Yii framework community
124 stars 50 forks source link

using econditionalvalidator with checkbox and dropdown #24

Open srakl opened 9 years ago

srakl commented 9 years ago

i have a checkbox is_new that when checked will enable a dropdown #Dealership_make_code

basically i'm trying to get my error checking to validate and make sure a dropdown option has been selected if the checkbox is checked.

If checkbox is NOT checked, dropdown can be empty. Here is my code

 array(
                'make_code', 'site.common.components.validate.EConditionalValidator',
                'conditionalRules' => array('is_new', 'compare', 'compareValue' => 1),
                'rule' => array('required'),
                'clientValidationJS' => "if ($('#Dealership_is_new :checkbox:checked').length > 0) {
                                            if ($('#Dealership_make_code').val().length === 0) {
                                                    alert($('#Dealership_make_code').val().length);
                                                    messages.push('cannot be empty');
                                                }
                                            }
                                         "      
            ),

i cant seem to get this to work, nor can i get the client side to work either. Any idea what i'm missing? Thanks