Skip to content

Format Field Data Before Validation #747

@ThatMorneGuy

Description

@ThatMorneGuy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    onholdWaiting feedback

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions