All Projects → michaelmob → django-semanticui-forms

michaelmob / django-semanticui-forms

Licence: MIT license
Effortlessly style all of your Django forms and form fields with Semantic UI wrappers.

Programming Languages

javascript
184084 projects - #8 most used programming language
python
139335 projects - #7 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to django-semanticui-forms

i7n-pdfhtml
pdfHTML is an iText 7 add-on for C# (.NET) that allows you to easily convert HTML and CSS into standards compliant PDFs that are accessible, searchable and usable for indexing.
Stars: ✭ 111 (+88.14%)
Mutual labels:  forms
django-safe-filefield
Secure file field, which allows you to restrict uploaded file extensions.
Stars: ✭ 41 (-30.51%)
Mutual labels:  forms
pancake
Pancake 是基于 Golang Gin 和 React Semantic UI 构建的个人博客
Stars: ✭ 15 (-74.58%)
Mutual labels:  semantic-ui
ember-lux-starter-app
A quick Ember + Lux boilerplate with authentication.
Stars: ✭ 14 (-76.27%)
Mutual labels:  semantic-ui
forest-templates
Source for https://semantic-ui-forest.com/templates/
Stars: ✭ 58 (-1.69%)
Mutual labels:  semantic-ui
form-o-fill-chrome-extension
The programmable form filler for developers. Powered by javascript.
Stars: ✭ 84 (+42.37%)
Mutual labels:  forms
pyladies-courseware
Homework/task submit and review web app · based on React and Python aiohttp
Stars: ✭ 14 (-76.27%)
Mutual labels:  semantic-ui
cl-forms
Web forms handling library for Common lisp
Stars: ✭ 29 (-50.85%)
Mutual labels:  forms
ember-formly
JavaScript powered forms for Ember
Stars: ✭ 24 (-59.32%)
Mutual labels:  forms
forms-frontend
Frontend for Python Discord forms.
Stars: ✭ 18 (-69.49%)
Mutual labels:  forms
form.js
🖍️ Automagic forms.
Stars: ✭ 16 (-72.88%)
Mutual labels:  forms
live-form-validation
⛔ Nice client-side live form validation for Nette Forms.
Stars: ✭ 55 (-6.78%)
Mutual labels:  forms
twilio-taskrouter-realtime-dashboard
Twilio TaskRouter Realtime Dashboard using Sync
Stars: ✭ 51 (-13.56%)
Mutual labels:  semantic-ui
vuejs-semantic-ui
Vue Semantic-UI boilerplate
Stars: ✭ 18 (-69.49%)
Mutual labels:  semantic-ui
Maily-Form
Forms on any website
Stars: ✭ 29 (-50.85%)
Mutual labels:  forms
boxdetect
BoxDetect is a Python package based on OpenCV which allows you to easily detect rectangular shapes like character or checkbox boxes on scanned forms.
Stars: ✭ 46 (-22.03%)
Mutual labels:  forms
react-final-form-listeners
A collection of components to listen to 🏁 React Final Form fields
Stars: ✭ 91 (+54.24%)
Mutual labels:  forms
real-time-todo
A real time todo list using websockets
Stars: ✭ 22 (-62.71%)
Mutual labels:  semantic-ui
ember-do-forms
ember-do-forms handles the icky parts of forms that you don't want to, and leaves the rest to you.
Stars: ✭ 18 (-69.49%)
Mutual labels:  forms
react-hubspot
A collection of React hooks for interacting with Hubspot APIs
Stars: ✭ 20 (-66.1%)
Mutual labels:  forms

Semantic UI for Django Forms

Effortlessly style all of your Django forms and form fields with Semantic UI wrappers.

Starting Off

  1. Install this django-semanticui-forms with pip or git.
pip install django-semanticui-forms
  1. Add semanticuiforms to your INSTALLED_APPS.
  2. Load the templatetags into your template {% load semanticui %}

Template Tag

To render a form, it's as simple as {% render_form my_form %}

It is possible to render each field individually allowing for more customization within the template. {% render_field my_form.field %}

Attributes

Form Attributes

Form attributes given to the template tag that are not specified for internal use are passed onto each field.

It is possible to exclude fields from render_form using the exclude parameter. Fields to be excluded should be separated by commas.

{% render_form my_form exclude='field1,field3' %}

For example: {% render_form my_form name='Hello' %} will add a name attribute to each field in that form.

For good use: {% render_form my_form _help=1 %} will display the field's help_text on all fields.

Field Attributes

Any attribute can be assigned to most fields. This can be done by either assigning within the form class or on-the-fly in the template.

In form class

field = forms.CharField(widget=forms.TextInput(attrs={"value": "Testing"}))

In template tag

{% render_field my_form.field value='My Value' placeholder='Put your text here!' %}

Specific attributes can modify how your fields are rendered. Private attributes start with a _ and will not be added to the field's attributes. These attributes can be set in the form class or as an argument like above.

  • _no_label: Do not show label
  • _no_required: Do not show required asterisk
  • _required: Do show required asterisk (assumes _no_required is absent)
  • _no_errors: Do not show inline errors
  • _inline: Adds inline class to field
  • _field_class: Allows for custom field classes
  • _override: Render as a different input type
  • _style: Stylize specific fields (BooleanField, ChoiceField)
    • BooleanField: set to 'toggle' or 'slider'
    • ChoiceField: set to 'search' or 'multiple' and more
  • _icon: Put icon on field
  • _dropdown_icon: Set dropdown icon for ChoiceFields, defaults to 'dropdown'
  • _help: Display help_text if available
  • _align: Used with _icon, which side icon is on; not required

Icons

Icons can be added to input fields easily. Add the attribute _icon and optionally _align to your arguments.

{% render_field my_form.field _icon='star' _align='left' %}

Custom/Overriding Fields

Override to render as different field

Overriding the function that renders the field is done using the _override attribute. This is useful for things like using CountrySelect as it is not its own field type.

Custom ChoiceFields

CountrySelect
CountrySelect from the django-countries package can be used to create a nice field that displays a list of countries alongside their flags, to access it you must set the _override attribute to CountrySelect.

Icon ChoiceField
IconSelect can be used with overriding just like CountrySelect. This field is useful since icons can be placed next to the values in the field.

# Python
# ("key", "value|icon")
choices = (
    ("male", "Male|man"),
    ("female", "Female|woman"),
    ("other", "Other|genderless"),
)

# Template
{% render_field my_form.gender _override='IconSelect' %}

Layouts

Using Semantic UI's form layout classes with Semantic UI Forms for Django is simple.
Within your form's Meta class, simply create a layout list. Within that list, create tuples with an function name as the first value, and the value as the second.

Functions names are as followed:

  • Text is for any text or HTML markup. Text in this is considered safe.
  • Field's value must be the name of a field.
  • [X] Fields are containers. It's value must include Field items or more [X] Field items. [X] should be replaced, either by a number or a class. All items inside this will be wrapped with a div that has the class of the key.
    • Four Fields
    • Six Fields
    • Inline Fields
    • Equal Width Fields

To set "wideness" of a specific field, you must add it to the _field_class attribute on your field. It cannot be done in the layout.

class ExampleLayoutForm(forms.Form):
    class Meta:
        layout = [
            ("Text", "<h4 class=\"ui dividing header\">Personal Details</h4>"),
            ("Three Fields",
                ("Field", "first_name"),
                ("Field", "middle_initial"),
                ("Field", "last_name"),
            ),

            ("Text", "<h4 class=\"ui dividing header\">More Details</h4>"),
            ("Inline Fields",
                ("Field", "website"),
                ("Field", "email"),
            ),

            ("Text", "<h4 class=\"ui dividing header\">Complicated Details</h4>"),
            ("Four Fields",
                ("Field", "first_name"),
                ("Field", "middle_initial"),
                ("Field", "last_name"),
                ("Two Fields",
                    ("Field", "username"),
                    ("Field", "email"),
                ),
            ),

            ("Field", "helpful")
        ]


    username = forms.CharField()
    first_name = forms.CharField()
    middle_initial = forms.CharField()
    last_name = forms.CharField()
    website = forms.CharField()
    email = forms.EmailField()
    phone_number = forms.CharField()
    helpful = forms.BooleanField()

Settings

Override wrappers by finding the wrapper variable name and prepending SUI_ to it and inserting it into your settings.py.

SUI_ERROR_WRAPPER = "<div class=\"ui red pointing prompt label\">%(message)s</div>"

You can also change the default placeholder text.

SUI_PLACEHOLDER_TEXT = "Select Option"

Basic Semantic UI Validation Generator

Semantic UI Forms for Django can generate a basic validation configuration for your form. The generator is very basic and does not have many features. It is only intended to give you a starting point.

View https://semantic-ui.com/behaviors/form.html for more details.

python manage.py semanticuivalidation app.forms.ExampleForm [--shorthand]

Testing

  1. Create a virtual environment.
virtualenv -p $(which python3) .env
  1. Source the activation script.
source .env/bin/activate
  1. Set current directory to the semanticuiforms app and then install Python requirements.
pip install -r requirements.txt
  1. Inside of the example app, make and run migrations for testing purposes.
python manage.py makemigrations 
python manage.py migrate 
  1. Run tests.
python manage.py test semanticuiforms 
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].