Search code examples
pythondjangoformsfieldsatchmo

How to prevent Satchmo forms from displaying asterisk after required fields?


I'm customizing my Satchmo store forms and have an icon that appears before any required fields. The problem is, Satchmo seems to want to render a text asterisk after the required fields. I'm using field.label to get this label, should I be using something else?

EDIT: All my form templates are hard coded. I have an inclusion tag that takes a field and wraps it in a standard field template I've developed. My template uses the {{ field.label }} to display the friendly name of the field. It seem the label itself has a single asterisk in it at the end.


Solution

  • What happens if you do the following?

    1. Copy some or all of Satchmo's form templates to a new location and modify them to remove the asterisks
    2. Arrange it so that your copies of those templates are seen before Satchmo's copies (by configuring the template loader settings appropriately, say by placing the app with the copied templates above Satchmo in settings.INSTALLED_APPS)

    Update: I'm not able to reproduce your results with a vanilla Satchmo 0.8.1 installation. Can you give some more information? Here's what I did: First, I modified templates/contact/update_form.html, which contains hard-coded asterisks. I could easily remove them by changing the template; they disappeared from the UI. Instead, I left them in but added immediately after, in parentheses, {{ form.field.label }} after each of the fields in a section of the form. This is the result:

    alt text

    The labels here do contain an asterisk - as I mentioned earlier, this is because ContactInfoForm hardcodes this behaviour in its __init__ method. You would have to undo this behaviour, perhaps by using a derived class which removes trailing *s from field labels.

    However, I did not find any *s appearing in other required fields. For example, here's a screenshot of the checkout form when I tried submitting without entering required information:

    alt text

    As you can see the credit card number and CCV are required fields but do not appear with an asterisk at the prompt. Nor do the labels have asterisks. So, the problem you are experiencing appears to be something to do with your customisations, but without more information it is difficult to be more helpful.