drop down multi checkbox with bootstraps selet

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

drop down multi checkbox with bootstraps selet

ايهاب توفيق

I am tring to create drop down checkbox with values from database   in my templet using bootstrap select and form MultipleChoiceField like this

 

Html

select class="selectpicker" multiple>

    {% for topping in form.the_topping %}

    <option value="{{ topping }}">{{ topping.topping_id }}</option>

 

    {% endfor %}

</select>

 

<script type="text/javascript">

$(document).ready(function() {

      $('.selectpicker').selectpicker({

    style: 'btn-info',

    size: 4

        });

                                });

</script>

Form.py

class ProfileForm(forms.ModelForm):
    the_topping = forms.ModelMultipleChoiceField(
queryset=Topping.objects.all(), required=False, widget=forms.CheckboxSelectMultiple)

   
class Meta:
        model = Pizza
        exclude = [
'user']

 

the bootstrp working and the form is working but doesnot combined

 

can any one help me PLS

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/27867c6f-995f-4d44-8980-6957e26f002b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

drop down multi checkbox with bootstraps selet

Camilo Torres
Hi,

You have to properly construct the <select> element.

Take a look at these sections of the manual:

https://docs.djangoproject.com/en/1.10/topics/forms/#rendering-fields-manually

https://docs.djangoproject.com/en/1.10/topics/forms/#looping-over-the-form-s-fields

Take a special look at field html_name; you should be using that as the name of your select element. The name is used to map the posted data to the form in the code.

Camilo.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c4cd95be-65c9-4435-b6bf-c90bde523079%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: drop down multi checkbox with bootstraps selet

ايهاب توفيق
In reply to this post by ايهاب توفيق
thank you for your help

بتاريخ السبت، 18 مارس، 2017 6:58:07 م UTC+2، كتب ايهاب توفيق:

I am tring to create drop down checkbox with values from database   in my templet using bootstrap select and form MultipleChoiceField like this

 

Html

select class="selectpicker" multiple>

    {% for topping in form.the_topping %}

    <option value="{{ topping }}">{{ topping.topping_id }}</option>

 

    {% endfor %}

</select>

 

<script type="text/javascript">

$(document).ready(function() {

      $('.selectpicker').selectpicker({

    style: 'btn-info',

    size: 4

        });

                                });

</script>

Form.py

class ProfileForm(forms.ModelForm):
    the_topping = forms.ModelMultipleChoiceField(
queryset=Topping.objects.all(), required=False, widget=forms.CheckboxSelectMultiple)

   
class Meta:
        model = Pizza
        exclude = [
'user']

 

the bootstrp working and the form is working but doesnot combined

 

can any one help me PLS

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ef81db93-c69b-427c-bd0e-c69ec75bd9a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...