chhantyal / taggit-selectize

Auto-complete/auto-suggestion for django-taggit (django-taggit + selectize.js)
BSD 3-Clause "New" or "Revised" License
68 stars 23 forks source link

Does this only work in admin ? #17

Closed brianbola90 closed 6 years ago

brianbola90 commented 6 years ago

can this be implemented in a user form ? Any Info on how to do this?

brianbola90 commented 6 years ago

from taggit_selectize import widgets as tag_widget

class PostForm(forms.ModelForm):
    class Meta:
        model = Post
        fields = ['title', 'text', 'tags', 'publish']
        widgets = {'title': forms.TextInput(attrs={'class': 'col-md-5 form-control', 'placeholder': 'Title'}),
                   'text': forms.Textarea(),
                   'tags': tag_widget.TagSelectize(attrs={'class': 'col-md-5', 'placeholder': 'Tags'}),
                   'publish': forms.CheckboxInput(attrs={'label': 'publish'})}```
brianbola90 commented 6 years ago

Fix above import the widget from taggit_selectize and use it in your form

make sure jquery is at the top of your html template.

uditvashisht commented 6 years ago

Hi, I have changed the form and I have also added the js and css files manually. Css in the head and js at the bottom just above the . I am still not able to use it outside the admin.

andytwoods commented 6 years ago

I detailed an example on stackoverflow recently that might help https://stackoverflow.com/a/51464694/960471

uditvashisht commented 6 years ago

@andytwoods Yes, I have gone through that multiple times. But since I am new to Django and Python few things there were complex for me . Let me explain you what I am doing. I have a blog application and I have added this in my models.py

tags = TaggableManager()

I have added this in class Meta of my post form

widgets = {'tags': tag_widget.TagSelectize()}

I have added the JS and CSS manually in my template. It still doens't work for me. Is there anything I can do apart from all this ?

andytwoods commented 6 years ago

I think Stackoverflow is a better place for this conversation.

But check to see if you have JS errors (via browser console). I suspect js ajax is not reaching your backend (urls.py needs configuring).

uditvashisht commented 6 years ago

@andytwoods Yes, I have configured my urls. I don't have enough reputation on stack so I couldn't comment on your post . However I have posted a question https://stackoverflow.com/questions/51844921/use-taggit-selectize-in-django-to-autocomplete-the-tags-in-user-form-outside-the . You can reply on this so that we can follow the conversation.

Also one more thing, I am using Martor Editor for the text of article, which uses semantic.js and the tags are on the same page. semantic.js has messed up my other JS. So, now I am loading them only in the Post Create form but selectize.js also loads on the same page. Could it be a reason ?

brianbola90 commented 6 years ago

Have you tried commenting out semantic.js qnd changing the order of them in the template

uditvashisht commented 6 years ago

@brianbola90 Hi yes, I just tried it it didn't work even after commenting out semantic.js. I have tried loading the selectize.js almost everywhere in the template (even in the head), right now I am loading it just under the jquery and above popup, bootstrap etc.

andreasnuesslein commented 5 years ago

I'm pretty sure the problem comes from jquery not being loaded soon enough, throwing a

})(jQuery || django.jQuery); X
   ^
Uncaught ReferenceError: jQuery is not defined

Try and put your <script src="{% static 'vendor/js/jquery-3.3.1.min.js' %}"></script> into the <head>.