Reputation: 1309
I have a select option in my laravel blade that allows the user to select a single industry type. My problem now, is if the user is in the confirm page already, and click the cancel button, the selected industry is not being selected in the dropdown menu. I can get its previous value but I can't select it in the drop down menu. Here's what I've done:
<select name="industry" v-model="industry" v-bind:class="{ error: industryError }">
@foreach(config('const.industry') as $i => $industry)
<option value="{{ $i }}" @if(old('industry' || $brand['industry']) == $i) selected @endif>{{ $industry }}</option>
//also done this {{ $brand['industry'] == $i ? 'selected="selected"' : '' }}
@endforeach
</select>
vue.js file
(function() {
"use strict";
new Vue({
el: '#regist_brand',
data: {
industry : null,
//other data
},
methods:{
//my methods
},
})();
Upvotes: 0
Views: 2612
Reputation: 1309
Thanks @nakov for the inputs, I'm able to solve my problem this way:
<select name="industry" v-model="industry" v-bind:class="{ error: industryError }">
@foreach(config('const.industry') as $i => $industry)
<option value="{{ $i }}">{{ $industry }}</option>
//also done this {{ $brand['industry'] == $i ? 'selected="selected"' : '' }}
@php
$industry = $brand['industry'];
@endphp
@endforeach
</select>
<script>
var industry = "{{ $industry }}";
</script>
vue.js file
(function() {
"use strict";
new Vue({
el: '#regist_brand',
data: {
industry : industry,
//other data
},
methods:{
//my methods
},
})();
Upvotes: 0
Reputation: 14278
The usage of the old
is wrong, the second parameter of the old
is a default value if none exists, so try this:
old('industry', $brand['industry'])
Also make sure that your $brand['industry']
contains the key(id) of the previously selected item. You can print it out to make sure in your option:
Debug like this:
<option value="{{ $i }}" @if(old('industry', $brand['industry']) == $i) selected @endif>{{ $industry . ' - ' . $i . ' - ' . $brand['industry']}}</option>
Upvotes: 1