0

im using django and i have a list of dates

list = ["2014-10-26","2010-05-05","1991-12-12" ... ] #This list may grow

I want create two comboboxes that have dates like this:

combobox1 = 2014-10-26
            2010-05-05
            1991-12-12

combobox2 = 2010-05-05
            1991-12-12

and when you select one date in combobox1 in the combobox2 all the dates before the selected disappear, is there a way of doing this? thanks!

edit:

list = ["2014-10-26","2010-05-05","1991-12-12","2015-11-26","200-05-05","1999-12-12"]

combobox1
    2014-10-26
    2010-05-05
    1991-12-12
    2015-11-26
    2000-05-05
    1999-12-12

user choose 1991-12-12, in the combobox2 will be like 

combobox2:
2015-11-26
2000-05-05
1999-12-12
Hook
  • 391
  • 5
  • 16
  • Need some more context...what do you mean by dissapear, give an example please...maybe adding what are you going to use it for could help too – cdvv7788 Oct 27 '14 at 03:38

1 Answers1

0

To create the select you will want to use a choice field:

YEAR_IN_SCHOOL_CHOICES = (
('FR', 'Freshman'),
('SO', 'Sophomore'),
('JR', 'Junior'),
('SR', 'Senior'),
)

myfield = forms.ChoiceField(choices=YEAR_IN_SCHOOL_CHOICES)

Just modify the argument you send as choices. The first value will be the value in your option and the second one will be the displayed text:

<option value="FR">Freshman</option>

You can use Jquery to do that in the client side using the change event:

$( "select" )
  .change(function () {
    var str = "";
    $( "#mySelectId option:selected" ).each(function() {
        if(this_shouldnt_show){
              $(this).hide();
        }
        else{
              $(this).show();
        }
    });
  });

You just need to figure out the condition for that to happen but that depends on what you are using in the value field. If you need to compare dates check this question then.

Community
  • 1
  • 1
cdvv7788
  • 2,021
  • 1
  • 18
  • 26
  • Ok, thanks :) i'll do this later, but my priority right now is take the elements of the list and put them in a normal – Hook Oct 27 '14 at 05:09
  • Yes! the list i mentioned earlier – Hook Oct 27 '14 at 05:23