如何根据另一个字段的返回来禁用一个字段的输出?

发布于 2024-10-14 09:33:07 字数 66 浏览 1 评论 0原文

在我看来,有些字段我宁愿根据另一个字段的值来隐藏。我正在寻找用代码或其他方式执行此操作但不启用 php 过滤器的方法。

There are fields in my view that I would rather hide depending on the value of another field. I am lookinf for ways to do it in code, or otherwise but without enabling php filter.

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

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

发布评论

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

评论(3

但可醉心 2024-10-21 09:33:07

不知道你用的是哪个版本的View。我不太记得 V2 中是否支持输出重写,但我想是的。在V3中,它就在那里,等待你使用它。

输出重写接受任何 HTML 代码,您可以使用查询返回的内容进行替换。我不确定你可以在那里使用 PHP,也许可以,但我从未真正尝试过。无论如何,假设您有 field_foofield_bar,并且两者都是一些选择选项或复选框或其他一些多项选择,在数据库中具有键值对(例如1|foo、2|bar 等)。

在这种情况下,您应该有四个可用选项:(

[field_foo_value]
[field_foo_value_raw]
[field_bar_value]
[field_bar_value_raw]

它们的命名可能有点不同,我不太记得确切的命名约定)。您可以像这样重写“bar”字段输出:

<span class="visibility-[field_foo_value_raw]">[field_bar_value]</span>

然后,假设“foo”的可能键是1和2,您可以编写一些CSS:

span.visibility-1 { display: inline; }
span.visibility-2 { display: none; }

如果允许使用PHP,它应该更容易,但我有一种感觉只能使用 HTML。无论如何,我希望这会有所帮助。

I don't know which version of Views you use. I can't quite remember whether output rewriting was available in V2, but I suppose it was. In V3, it's there, waiting for you to use it.

Output rewriting accepts any HTML code and you can use replacements from what the query returned. I'm not sure you can use PHP there, perhaps you can, but I've never really tried. Anyways, let's say you have field_foo and field_bar, and that both are some select options or checkboxes or some other multiple choice thing, having key-value pairs in the database (like 1|foo, 2|bar etc.).

In this situation, you should have four options available:

[field_foo_value]
[field_foo_value_raw]
[field_bar_value]
[field_bar_value_raw]

(they'll probably be named a bit differently, I can't quite remember the exact naming convention). You can rewrite the "bar" field output like this:

<span class="visibility-[field_foo_value_raw]">[field_bar_value]</span>

Then, assuming the possible keys for "foo" are 1 and 2, you can write some CSS:

span.visibility-1 { display: inline; }
span.visibility-2 { display: none; }

If PHP is allowed, it should be even easier, but I have a feeling you can only use HTML. Anyway, I hope this helps.

把梦留给海 2024-10-21 09:33:07

使用 hook_form_alter hook_form_FORM_ID_alter您可以更改views_exposed_form表单。从那里,应该可以使用CTools' 依赖设置字段之间的可见性依赖关系。视图的公开表单布局在主题层中部分处理(请参阅 views-exposed- form.tpl.php),因此可能需要更多的工作来隐藏/显示标签。

Using hook_form_alter or hook_form_FORM_ID_alter you can alter the views_exposed_form form. From there, it should be possible to use CTools' Dependent to set visibility dependencies between fields. Views's exposed form layout is partially handled in the theme layer (see views-exposed-form.tpl.php) so more work is probably needed to hide/show the labels.

拥抱影子 2024-10-21 09:33:07

这个模块看起来可以满足您的需求。我已经使用过它,它设置简单且使用快捷。

http://drupal.org/project/conditional_fields

This module seams like it would do what you need. I've used it and it's easy to setup and quick to use.

http://drupal.org/project/conditional_fields

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