0

I am trying to implement a datepicker in a user profile page, but it is not presenting the datepicker when I click on the textfield. Any thoughts?

class ProfileForm(forms.ModelForm):
    class Meta:
        model = Profile
        fields = ('birth_date', )
        widgets = {
            'birth_date': forms.DateInput(attrs={'class': 'form-control'}),
        }
arcade16
  • 1,535
  • 4
  • 23
  • 45

2 Answers2

1

Install datapicker library and jquery-ui and in your template https://jqueryui.com/datepicker/

<script type="text/javascript">
    $(function(){
        $( "#id_birth_date" ).datepicker({
          yearRange: "-120:+0",
          changeMonth: true,
          changeYear: true,
          dateFormat: "yy-mm-dd",
          beforeShow: function() {
          setTimeout(function(){
            $('.ui-datepicker').css('z-index', 9999);
        }, 0);
    }});
  });
</script>
erajuan
  • 2,224
  • 20
  • 31
  • This answer along with this post solved my problem: http://stackoverflow.com/questions/20700185/how-to-use-datepicker-in-django – arcade16 May 02 '17 at 23:55
1

Supposing that django provide datepicker for DateField by default. The problem may be that when you add widget to add class form-control ,It resets all the default class that are applied by django . Try removing your class

Your problem may be solved by this post

Community
  • 1
  • 1
rand0mb0t
  • 124
  • 1
  • 13