Last active
December 17, 2015 19:09
-
-
Save gladson/5658444 to your computer and use it in GitHub Desktop.
Add parâmetro no forms | ul_attrs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
from .widgets import MyCheckboxSelectMultiple | |
class Form(forms.Form): | |
ability = forms.ChoiceField( | |
widget= MyCheckboxSelectMultiple(ul_attrs={"class":"fancybox"}), | |
choices = SKILLS, | |
required=False | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
from django.forms.util import flatatt | |
from django.utils.safestring import mark_safe | |
class MyCheckboxSelectMultiple(forms.CheckboxSelectMultiple): | |
def __init__(self, attrs=None, ul_attrs=None): | |
self.ul_attrs = ul_attrs | |
super(MyCheckboxSelectMultiple, self).__init__(attrs) | |
def render(self, name, value, attrs=None, choices=()): | |
html = super(MyCheckboxSelectMultiple, self).render(name, value, attrs, choices) | |
final_attrs = self.build_attrs(self.ul_attrs) | |
return mark_safe(html.replace('<ul>','<ul%s>' % flatatt(final_attrs))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment