Drupal Views 和公开的过滤器 - 如何重置可选的下拉列表过滤器,或允许“全部”过滤器选择
我有一个按国家/地区过滤的视图。国家/地区是可选的 CCK 文本字段,可从预定义列表中通过下拉列表进行选择。
当我将该字段公开为可选视图搜索过滤器时,我可以在过滤器表单上选择一个国家/地区,但如何处理不选择的情况?我希望用户能够“取消选择”任何先前选择的值,以便查询针对所有国家/地区运行(或者,更准确地说,不按国家/地区限制结果)。由于显而易见的原因,我无法将“all”作为值添加到 CCK 字段。在搜索过滤器的下拉列表中选择所有国家/地区不太人性化,并且会导致页面超时(列表中有超过 200 个国家/地区,我只能想象生成的 SQL 查询)。处理这个问题的最佳方法是什么?
我发现这个 View Filters Reset hack 可能会有所帮助。记住最后一个选择的愿望增加了另一个复杂性 - 当在视图属性中配置时,一旦设置(持久)cookie,就无法摆脱选择(除非手动删除 cookie)。
I have a view with a filter by country. Country is an optional CCK text field with drop-down list selection from a predefined list.
When I expose the field as an optional view search filter, I can select a country on the filter form just fine, but how can I handle no selection? I want the user to be able to "un-select" any previously selected value so that the query runs for all countries (or, to be more precise, does not constrain the results by country). I cannot add "all" as a value to the CCK field for obvious reasons. Selecting all countries in the drop-down on the search filter is not very user-friendly and causes the page to time out (there are over 200 countries in the list, and I can only imagine the resulting SQL query). Whats the best way to handle this?
I found this View Filters Reset hack which could be helpful. The desire to memorize the last selection adds another complication - when configured in the View properties, and once the (persistent) cookie is set, there is no way to get rid of the selection (short of manually deleting the cookie).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是检查过滤器属性上的“强制单一”。这使得
在国家/地区过滤器下拉列表中显示为一个选项。这是有道理的,因为多选列表中的
可能会被视为不明确。尽管如此,我仍然可以想到为什么多重选择过滤器可能是可选的。 Drupal 每天都给我带来惊喜。The answer was to check "Force Single" on the filter properties. This made
<any>
show up as a selection in the country filter drop-down. It kind of makes sense, because<any>
in a multiple-selection list could be seen as ambiguous. Still, I can think of valid reasons why a multiple selection filter might be optional. Drupal surprises me every day.