私は2つの要素のフォームを持っています.最初の要素は常に必要ですが、2番目は最初の要素の値に依存しますFashion Designers
.Fashion Illustrators
最初の要素の値がそれ以外の場合、2 番目の要素は依然として表示されず、必須ではありません。
ここに私のコードがあります:
<form action="" method="post" id='career' enctype="multipart/form-data">
<div class="col-xs-12 col-lg-3 paddingleft">
<div style="margin-bottom:20px" class="form-group">
<select id="vacancy" name="vacancy" class="form-control">
<option value="" disabled selected>Select career</option>
<option value="Fashion Designers">Fashion Designers</option>
<option value="Fashion Illustrators">Fashion Illustrators</option>
<option value="Tailor">Tailors</option>
<option value="Tailor's Assistant">Tailor's Assistants</option>
<option value="Human Resources">Human Resources</option>
<option value="Marketing coordinators">Marketing Coordinators</option>
<option value="Sales coordinators">Sales Coordinators</option>
<option value="Accountants">Accountants</option>
<option value="Production Managers">Production Managers</option>
</select>
</div>
<div style="margin-bottom:20px" class="form-group">
<input type="file" name="portfolio" id="portfolio">
</div>
<div style="margin-bottom:20px" class="form-group">
<input type="submit" class="btn btn-default pull-right" data-toggle="modal" data-target=".bs-example-modal-sm" value="Submit">
</div>
</div>
</form>
<script type="text/javascript">
$('#career')
.bootstrapValidator({
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
vacancy: {
validators: {
notEmpty: {
message: 'Vacancy is required.'
},
}
},
portfolio: {
validators: {
notEmpty: {
message: 'Portfolio is required.'
},
callback: {
message: 'Portfolio is required.',
callback: function (value, $field) {
if ($field.style.display === 'none') {
return true;
} else if (value != null) {
return true;
}
}
}
}
},
}
});
</script>
エラーが発生しました:Uncaught TypeError: Cannot read property 'display' of undefined