Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this only work in admin ? #17

Closed
brianbola90 opened this issue Mar 30, 2018 · 10 comments
Closed

Does this only work in admin ? #17

brianbola90 opened this issue Mar 30, 2018 · 10 comments

Comments

@brianbola90
Copy link

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

@brianbola90
Copy link
Author

brianbola90 commented Apr 6, 2018

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
Copy link
Author

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
Copy link

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
Copy link
Contributor

andytwoods commented Aug 15, 2018

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

@uditvashisht
Copy link

@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
Copy link
Contributor

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
Copy link

@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
Copy link
Author

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

@uditvashisht
Copy link

@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
Copy link

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>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants