如何防止 Satchmo 表单在必填字段后显示星号?
我正在自定义我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您执行以下操作,会发生什么情况?
settings.INSTALLED_APPS
中 Satchmo 上方的模板)更新: 我无法通过普通 Satchmo 0.8.1 安装重现您的结果。 你能提供更多信息吗? 这就是我所做的:首先,我修改了
templates/contact/update_form.html
,其中包含硬编码的星号。 我可以通过更改模板轻松删除它们; 它们从用户界面中消失了。 相反,我将它们保留在其中,但立即在表单的一部分中的每个字段后面的括号中添加了{{ form.field.label }}
。 这是结果:这里的标签确实包含一个星号 - 正如我之前提到的,这是因为
ContactInfoForm
在其__init__
方法中硬编码此行为。 您必须撤消此行为,也许可以使用派生类从字段标签中删除尾随的*
。但是,我没有发现任何
*
出现在其他必填字段中。 例如,以下是我尝试提交而不输入所需信息时的结帐表单屏幕截图:如您所见,信用卡号和 CCV 是必填字段,但在提示时不会显示星号。 标签也没有星号。 因此,您遇到的问题似乎与您的自定义有关,但如果没有更多信息,就很难提供更多帮助。
What happens if you do the following?
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: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: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.