Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send ajax request with city id to get region #116

Open
ehabfoad opened this issue May 1, 2018 · 2 comments
Open

Send ajax request with city id to get region #116

ehabfoad opened this issue May 1, 2018 · 2 comments

Comments

@ehabfoad
Copy link

ehabfoad commented May 1, 2018

السؤال بخصوص ربط ال الدول بالمدن بحيث تظهر عن اختيار الدولة المدن الخاص بها

نفذت نفس الفكرة المعمولة فى الفيديو ده
Laravel 5.4 Larafalt Send ajax request with country id to get state
لا تعمل معى
انا استخدم laraflat 3
حاولت استخدام طريقة اسهل بالكود المرفق
data-secid in region
مش بيجى جواها الid صح

<script type="text/javascript">
    window.onload = function() {
    var sections = document.querySelector(".sections");
    sections.onchange = function () {
        var secId = this.value;
        var s_Sections = document.querySelectorAll(".subsection>option");
        var x = 0;
        while (x < s_Sections.length) {
            if(s_Sections[x].dataset.secid == secId){
                s_Sections[x].classList.add("active");
            }
            else{
                s_Sections[x].classList.remove("active");
            }
            x++;
        }
        document.querySelectorAll(".subsection>option[data-secid="+secId+"]")[0].setAttribute("selected",true);
    }
}
</script>




<div class="col-sm-3">
<div class="form-group {{ $errors->has("city") ? "has-error" : "" }}">
<label for="city">{{ trans( "city.city") }}</label>
	@php $cities = App\Application\Model\City::pluck("title" ,"id")->all()  @endphp
	@php  $city_id = isset($item) ? $item->city_id : null @endphp
	<select name="city_id "  class="form-control sections" id="city" > 
	@foreach( $cities as $key => $relatedItem)
  <option value="{{ $key }}"  {{ $key == $city_id  ? "selected" : "" }}> {{ is_json($relatedItem) ? getDefaultValueKey($relatedItem) :  $relatedItem}}</option>
	@endforeach
</select>
	@if ($errors->has("city"))
	<div class="alert alert-danger">
<span class="help-block">
	<strong>{{ $errors->first("city") }}</strong>
	</span>
	</div>
	@endif
	</div>

 </div>
   <div class="col-sm-3">
   <div class="form-group {{ $errors->has("region") ? "has-error" : "" }}">
 <label for="region">{{ trans( "region.region") }}</label>
   @php $regions = App\Application\Model\Region::pluck("title" ,"id")->all()  @endphp
     @php  $region_id = isset($item) ? $item->region_id : null @endphp
   @php  $city_id = isset($item) ? $item->city_id : null @endphp

  <select name="region_id "  class="form-control subsection" id="regions">
                                                            
   @foreach( $regions as $keys => $relatedItem )
  <option value="{{ $keys }}"  {{ $keys == $region_id   }} data-secid="{{ $key }}" {{ $key == $city_id  }}> {{ is_json($relatedItem) ? getDefaultValueKey($relatedItem) :  $relatedItem}}</option> 
                                                           
 @endforeach
</select>
 @if ($errors->has("region"))
 <div class="alert alert-danger">
<span class="help-block">
   <strong>{{ $errors->first("region") }}</strong>
   </span>
   </div>
 @endif
</div>

 </div>

@FoushWare
Copy link

سؤال بس . هل حليت مشكلة انك تضيف
new method like getUser() to the controller and get permission to use it
لاني مش عارف اعملها الصراحة
@ehabfoad

@ehabfoad
Copy link
Author

ehabfoad commented May 5, 2018

مع الاسف لسه محلتش المشكلة
@AhmedFouad60
@zizohassan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants