How can I validate my Other input field in Laravel 4.2 which appears after choosing Other option in a dropdown list? The values from my dropdown list are already required, now I want to apply the same loggic of validation with errors on my input field so that both are required! By fulfilling the first validation rule from the dropdown list the second validation rule from the input field ouputs the error! Whats the easiest way to solve this!
<div class="row">
<div class="col-lg-6 col-sm-6 col-md-6">
<script type="text/javascript">
function showfield(name){
if(name=='Other')document.getElementById('div1').innerHTML='<input class="custom-input" placeholder="Roles" style="margin-left: 32px;" name="roles" type="text" value/>';
else document.getElementById('div1').innerHTML='';
}
</script>
<select id="otherField" name="role" onchange="showfield(this.options[this.selectedIndex].value)">
<option value="" selected="selected">Select role</option>
<option value="UI/UX designers">UI/UX designers</option>
<option value="QA engineers">QA engineers</option>
<option value="Developer">Developer</option>
<option value="Scrum Master">Scrum Master</option>
<option value="CEO">CEO</option>
<option value="Director">Director</option>
<option value="Other">Other</option>
</select>
<div id="div1" class="row">
<div class="col-lg-6 col-sm-6 col-md-6"></div>
</div>
<div class="col-md-6">
@if($errors->first('roles') )
<div class="fe-form-error">
<div class="icon"></div>
{{ $errors->first('roles') }}
</div>
@endif
</div>
</div>
<div class="col-md-6">
@if($errors->first('role') )
<div class="fe-form-error">
<div class="icon"></div>
{{ $errors->first('role') }}
</div>
@endif
</div>
</div>
My class with validation rules:
class OnEventRegistration extends AbstractValidator {
protected $customRules = false;
protected $rules = array(
'email' => 'required|email|unique:users',
'password' => 'required|min:8|confirmed',
'first_name' => 'required',
'last_name' => 'required',
'role' => 'required',
'roles' => 'required',
);
}