Using jQuery Validate, I am doing a conditional validation on a select and a text field: the text field (#specialization) must be filled if a particular option (<option value="doctor">) was choosen from the select field (#job)
So far so good, here is a working copy: https://jsfiddle.net/vzx9paxz/2/
Now, I don't like to mess with too much JS code and I'd like to take advantage of the data-rule-required attribute. So, I'd like to evaluate the expression ($('#job').val() === 'doctor') directly in the HTML code, removing it from the Javascript: if it returns true, the #specialization field must be filled, otherwise it can be empty
Something like this:
<input type="text" data-rule-required="return ($('#job').val() === 'doctor')" class="form-control" id="specialization" name="specialization">
Of course this code doesn't work: I tried other expressions, like javascript:return ($('#job').val() === 'doctor') but with no luck at all...