Skip to content

Commit

Permalink
Updating documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeUrban committed Dec 4, 2019
1 parent e3ec78e commit 5c2be25
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
23 changes: 20 additions & 3 deletions docs/integrations/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Registering Integrations
Form Integrations
-----------------

.. _Bulma: https://bulma.io/documentation
.. _Django Forms: https://docs.djangoproject.com/en/2.2/topics/forms/#forms-in-django

Polaris uses `Django Forms`_ for collecting users' information, like their
Expand All @@ -53,8 +54,12 @@ You should be familiar with `Django Forms`_ and how they validate their inputs.

class MyDepositForm(TransactionForm):
"""This form accepts the amount to deposit from the user."""
first_name = forms.CharField()
last_name = forms.CharField()
first_name = forms.CharField(
widget=forms.widgets.TextInput(attrs={"class": "input"})
)
last_name = forms.CharField(
widget=forms.widgets.TextInput(attrs={"class": "input"})
)

def clean(self):
data = self.cleaned_data
Expand All @@ -74,7 +79,19 @@ You should be familiar with `Django Forms`_ and how they validate their inputs.
``TransactionForm`` already collects the deposit amount and asset type and
validates that the amount is within the asset's accepted deposit range. In
this example, we've also added some contact information to the form fields
and ensure they aren't left empty.
and validation that ensures they're not empty.

Polaris uses default CSS provided by Bulma_ for styling forms. To keep the
UX consistent, make sure to pass in a modified `widget` parameter to all
form fields displaying text like so:

::

widget=forms.widgets.TextInput(attrs={"class": "input"})

The `attrs` parameter adds a HTML attribute to the `<input>` tag that Bulma
uses to add better styling. You may also add more Bulma-supported attributes
to Polaris forms.

Polaris will also call the form's ``after_validation()`` function,
which in this case saves the form data collected to the database.
Expand Down
2 changes: 1 addition & 1 deletion polaris/polaris/integrations/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TransactionForm(forms.Form):
"""
amount = forms.FloatField(
min_value=0,
widget=forms.NumberInput()
widget=forms.NumberInput(attrs={"class": "input"})
)
asset = None

Expand Down
5 changes: 5 additions & 0 deletions polaris/polaris/templates/deposit/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@

{% for field in form %}
<div class="field">
{% if field.name == 'amount' %}
<label class="label">{{ field.label }}</label>
<div class="control has-icons-left">
{{ field }}
<span class="icon is-left">
<i class="fas fa-dollar-sign"></i>
</span>
</div>
{% else %}
<label class="label"> {{ field.label }}</label>
<div> {{ field }} </div>
{% endif %}

{% if field.errors %}
<p class="help is-danger">
Expand Down
6 changes: 4 additions & 2 deletions polaris/polaris/withdraw/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ class WithdrawForm(TransactionForm):

bank_account = forms.CharField(
min_length=0,
help_text="Enter the bank account number for withdrawal."
help_text="Enter the bank account number for withdrawal.",
widget=forms.widgets.TextInput(attrs={"class": "input"})
)
# TODO: Replace the bank with a ChoiceField.
bank = forms.CharField(
min_length=0,
help_text="Enter the bank to withdraw from."
help_text="Enter the bank to withdraw from.",
widget=forms.widgets.TextInput(attrs={"class": "input"})
)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="django-polaris",
version="0.9.6",
version="0.9.7",
description="A SEP-24-compliant Django anchor server",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 5c2be25

Please sign in to comment.