Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add admin support #25

Open
wants to merge 1 commit into from

4 participants

Andrey Grygoryev domob-podgorski Yusuf (Josè) Luis FunkyLoveCow
Andrey Grygoryev

to fix issue #15

FunkyLoveCow

This does not function when there are two inlines and the second depends on values in the first. The first inline behaves as expected, but the second one has all blank fields.

domob-podgorski

Superb GRAndSE. Your feature help me a lot. Thank you so much.
It worked like a charm.

Yusuf (Josè) Luis

This have much conflicts, is neccesary fix it for merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 16 deletions.
  1. +24 −16 smart_selects/widgets.py
40 smart_selects/widgets.py
View
@@ -2,7 +2,6 @@
from django.conf import settings
from django.forms.widgets import Select
from django.core.urlresolvers import reverse
-from django.utils.encoding import iri_to_uri
from django.utils.safestring import mark_safe
from django.db.models import get_model
import locale
@@ -82,12 +81,12 @@ def render(self, name, value, attrs=None, choices=()):
}
$(document).ready(function(){
- function fill_field(val, init_value){
+ function fill_field(id, val, init_value){
if (!val || val==''){
options = '<option value="">%(empty_label)s<'+'/option>';
- $("#%(id)s").html(options);
- $('#%(id)s option:first').attr('selected', 'selected');
- $("#%(id)s").trigger('change');
+ $(id).html(options);
+ $(id+' option:first').attr('selected', 'selected');
+ $(id).trigger('change');
return;
}
$.getJSON("%(url)s/"+val+"/", function(j){
@@ -95,28 +94,37 @@ def render(self, name, value, attrs=None, choices=()):
for (var i = 0; i < j.length; i++) {
options += '<option value="' + j[i].value + '">' + j[i].display + '<'+'/option>';
}
- $("#%(id)s").html(options);
- $('#%(id)s option:first').attr('selected', 'selected');
+ $(id).html(options);
+ $(id+' option:first').attr('selected', 'selected');
var auto_choose = %(auto_choose)s;
if(init_value){
- $('#%(id)s option[value="'+ init_value +'"]').attr('selected', 'selected');
+ $(id+' option[value="'+ init_value +'"]').attr('selected', 'selected');
}
if(auto_choose && j.length == 1){
- $('#%(id)s option[value="'+ j[0].value +'"]').attr('selected', 'selected');
+ $(id+' option[value="'+ j[0].value +'"]').attr('selected', 'selected');
}
- $("#%(id)s").trigger('change');
+ $(id).trigger('change');
})
}
- if(!$("#id_%(chainfield)s").hasClass("chained")){
+ if(!$("#id_%(chainfield)s").hasClass("chained")) {
var val = $("#id_%(chainfield)s").val();
- fill_field(val, "%(value)s");
+ if ("%(value)s" != 'None') {
+ fill_field(val, "%(value)s"); }
}
- $("#id_%(chainfield)s").change(function(){
- var start_value = $("#%(id)s").val();
- var val = $(this).val();
- fill_field(val, start_value);
+ $("#id_%(chainfield)s").change(function() {
+ var self = $(this);
+ var curr_parts = self.attr('id').split('-');
+ var base_parts = "%(id)s".split('-');
+ var id = '#';
+ for (var i = 0; i < curr_parts.length-1; i++) {
+ id += curr_parts[i] + '-';
+ }
+ id += base_parts[base_parts.length-1];
+ var start_value = $(id).val();
+ var val = self.val();
+ fill_field(id, val, start_value);
})
})
})(jQuery || django.jQuery);
Something went wrong with that request. Please try again.