Any insight on this is very much appreciated.
Aug 30, 2016
5
Level 1
Dependent Dropdowns, Options Not Returned
Hello! I'm trying to create multi-level dependent dropdowns using this plugin: https://github.com/kartik-v/dependent-dropdown but the options for the second selection are not showing up. Here is my code:
The View
<div class="form-group col-md-4">
<label for="country_name">Country</label>
<select class="form-control" name="country_name" id="countrySelector{{ $memberprofile->id }}">
<option></option>
@foreach( $countries as $country)
<option value="{{ $country->id }}">{{ $country->name }}</option>
@endforeach
</select>
</div>
<div class="form-group col-md-4">
<label for="region_name">Region</label>
<select class="form-control" name="region_name" id="regionSelector{{ $memberprofile->id }}">
</select>
</div>
JQuery script
// Region Selector
$("#regionSelector{{ $memberprofile->id }}").depdrop({
depends: ['countrySelector{{ $memberprofile->id }}'],
url: '{{ URL::route('regionselect') }}'
});
Route
Route::get('/regionselect', ['as' => 'regionselect', 'uses' => 'User\MemberProfileFormController@regionSelector']);
Controller
public function regionSelector(Request $request)
{
$childregions = ""; // define output variable
$countryname = 'Philippines';
$country = Country::where('name','=', $countryname)->first();
$countryid = $country->id;
$regions = Region::where('country_id', '=', $countryid)->get();
return Response::json(['output'=>$regions, 'selected'=>'']);
}
When I load the route {{ URL::route('regionselect') }} in the browser, the region options are being returned correctly but in the actual form the regions are not returned. It just says "Loading...".
How do I properly return the options for the region selection? Thank you for the help.
Please or to participate in this conversation.