pallets-eco / pallets-eco/wtforms
Bidirectional form data filters
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.6k
- Forks
- 409
- PR merge metrics
- No merged PRs in 30d
Description
I use a custom filter to add the currency prefix to a FloatField to make it more user friendly. This also adds the currency prefix to the value in my edit form.
from app import app
@app.template_filter()
def format_currency(value:float, currency:str=None):
if currency == 'AUD':
return "AU${:,.2f}".format(value)
else:
return "${:,.2f}".format(value)
from app._filters import format_currency
class ContractForm(Form):
cost = FloatField('Cost', id='contract_cost', default=0.00, filters=[format_currency])
Is it possible (and how would one implement) to use a filter to remove the currency prefix from the field data on submit before form validation?
I have gone through documentation and searched forums but haven't found a solution.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the FloatField usage and the custom filter in app/_filters.py, then trace when filters run relative to form submission and validation. Determine whether the currency prefix can be removed before FloatField validation while preserving the existing formatted display value. Done means a submitted prefixed currency value is accepted and validated as a number without breaking the edit-form output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100