如何防止 Satchmo 表单在必填字段后显示星号?

发布于 2024-08-01 21:24:49 字数 284 浏览 4 评论 0原文

我正在自定义我的 Satchmo 商店表单,并在任何必填字段之前显示一个图标。 问题是,Satchmo 似乎想在必填字段后呈现一个文本星号。 我正在使用 field.label 来获取此标签,我应该使用其他东西吗?

编辑:我的所有表单模板都是硬编码的。 我有一个包含标签,它接受一个字段并将其包装在我开发的标准字段模板中。 我的模板使用 {{ field.label }} 来显示字段的友好名称。 标签本身的末尾似乎有一个星号。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自在安然 2024-08-08 21:24:49

如果您执行以下操作,会发生什么情况?

  1. 将 Satchmo 的部分或全部表单模板复制到新位置并修改它们以删除星号
  2. 对其进行排列,以便在 Satchmo 的副本之前看到这些模板的副本(通过适当配置模板加载器设置,例如将应用程序与复制的副本放在一起) settings.INSTALLED_APPS 中 Satchmo 上方的模板)

更新: 我无法通过普通 Satchmo 0.8.1 安装重现您的结果。 你能提供更多信息吗? 这就是我所做的:首先,我修改了 templates/contact/update_form.html,其中包含硬编码的星号。 我可以通过更改模板轻松删除它们; 它们从用户界面中消失了。 相反,我将它们保留在其中,但立即在表单的一部分中的每个字段后面的括号中添加了 {{ form.field.label }} 。 这是结果:

alt text

这里的标签确实包含一个星号 - 正如我之前提到的,这是因为 ContactInfoForm 在其 __init__ 方法中硬编码此行为。 您必须撤消此行为,也许可以使用派生类从字段标签中删除尾随的 *

但是,我没有发现任何 * 出现在其他必填字段中。 例如,以下是我尝试提交而不输入所需信息时的结帐表单屏幕截图:

alt text

如您所见,信用卡号和 CCV 是必填字段,但在提示时不会显示星号。 标签也没有星号。 因此,您遇到的问题似乎与您的自定义有关,但如果没有更多信息,就很难提供更多帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文