Created
July 27, 2018 19:08
-
-
Save olivx/551817a54b20c1bc606bdb9422c47d18 to your computer and use it in GitHub Desktop.
Feed when change the value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $('#id_job_department').change(function(event) { | |
| var department_pk = $(this).val() | |
| url = "{% url 'json_sub_department' %}" | |
| if ($(this).children('option:first-child').is(':selected')) { | |
| $('#id_job_sub_department').children('option:not(:first)').remove(); | |
| }else{ | |
| $.ajax({ | |
| dataType:'json', | |
| data: {'pk': department_pk}, | |
| url: url, | |
| success: function(data){ | |
| $('#id_job_sub_department').children('option:not(:first)').remove(); | |
| $.each(data, function(index, value) { | |
| $('#id_job_sub_department').append($('<option>',{ value: index, text : value})); | |
| }); | |
| } | |
| }); | |
| }// else | |
| return false; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="col-sm-6"> | |
| <div class="form-group"> | |
| <label class='text-muted'> | |
| {% trans "Depto" %} | |
| </label> | |
| <p> | |
| <small>{% trans "Se sim, selecione uma opção" %}</small> | |
| </p> | |
| <select class="form-control" id="id_job_department" name="job_department"> | |
| <option value="">{% trans "Escolher" %}</option> | |
| {% for department in department_list %} | |
| <option value="{{ department.pk }}">{{ department|title }}</option> | |
| {% endfor %} | |
| </select> | |
| </div> | |
| </div><!-- end col --> | |
| <div class="col-sm-6"> | |
| <div class="form-group"> | |
| <label class='text-muted'> | |
| {% trans "Sub Depto" %} | |
| </label> | |
| <p> | |
| <small>{% trans "Se sim, selecione uma opção" %}</small> | |
| </p> | |
| <select class="form-control" id="id_job_sub_department" name="job_sub_department"> | |
| <option value="">{% trans "Escolher" %}</option> | |
| </select> | |
| </div> | |
| </div><!-- end col --> | |
| </div><!-- end row --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| url(r'dashboard/jobcombo/availablesubdepartment/$', views.json_sub_department , name='json_sub_department'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def json_sub_department(request): | |
| pk = request.GET.get('pk') | |
| data = {} | |
| if pk: | |
| sub_deparments = SubDepartment.objects.filter(department__pk=pk) | |
| for sub in sub_deparments: | |
| text = getattr(sub, 'sub_department') | |
| data[sub.pk] = text.title() | |
| return JsonResponse(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment