尝试编写 Drupal 日历输入黑名单
我正在创建一个带有基于日期时间的 javascript 弹出日历输入的 Drupal 表单,该表单允许用户设置想要取走或放下物品的日期。但是,我找不到一种方法来限制可选择作为输入的日期。例如,如果我们只在周一至周三至周五营业,我不希望人们能够使用选择器来表明他们想要在周日取货。
我一直在寻找日历输入验证和可用的阻止机制,但到目前为止还没有运气。
I'm creating a Drupal form with a datetime-based javascript popup calendar input that allows users to set a date for when they want to pick something up or drop it off. However, I can't find a way to limit what dates are selectable as input. For example, if we're only open Monday-Wednesday-Friday, I don't want people to be able to use the selector to indicate they want a pickup on Sunday.
I've looked far and low for calendar input validation and a usable blocking mechanism, but so far no luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Drupal 使用 jQuery 日期选择器来选择日期。我还没有研究过 Date 模块是如何实现 js 的,但是你也许可以向它添加额外的选项。或者,您可以自己添加日期选择器。您可以使用 jQuery 日期选择器非常轻松地获得您想要的内容:
beforeShowDay 是一个每天运行的函数,并且应该返回一个列表,其中第一项是一个布尔值,决定您的日期是否可选。第二个值是要添加的可选类,还有第三个值也可以使用,但现在不记得它的用途。
Drupal uses the jQuery datepicker to pick dates. I haven't looked at how the Date module implements the js, but you can probably add extra options to it. Alternatively, you can just add the datepicker yourself. You can get what you want with the jQuery datepicker pretty easily:
beforeShowDay is a function that is run for each day and should return a list where first item is a boolean that decides if you day is selectable. The second value is an optional class to add and there is a third that can be used as well, but can't remember what that is for right now.
我认为你最好的选择是找到你能找到的最简单的日期选择器(因为最简单的通常==最容易修改)并对其进行硬编码以跳过在构建日期选择器时你不想要的日子。
然而,这仅修复了它的 JS 方面,因此您可能需要编写一个小的自定义模块来执行服务器端验证。
I think your best bet is to find the simplest datepicker you can find (because simplest usually == easiest to modify) and just hardcode it to skip over the days you don't want when it's building the datepicker.
However, that only fixes the JS side of it, so you'll probably want to write a little tiny custom module that does server side validation as well.