简体   繁体   English

如何编写脚本来限制过去日期的 Ninja Form 日期选择器?

[英]How to write a script to restrict Ninja Form date picker for past dates?

I have a date picker field in my WordPress Website using the Ninja Forms Plugin.我使用 Ninja Forms 插件在我的 WordPress 网站中有一个日期选择器字段。 I don't think the plugin gives me the option to restrict past dates.我不认为该插件让我可以选择限制过去的日期。 So I want to achieve that the user can not pick any past dates.所以我想实现用户不能选择任何过去的日期。

I have of course tried to google a solution but I am not really good with javascript/jquery and don't understand how I can achieve this.我当然试图用谷歌搜索一个解决方案,但我对 javascript/jquery 并不是很擅长,也不明白我如何实现这一点。 Can anyone help?任何人都可以帮忙吗? Many thanks in advance!提前谢谢了!

It appears Ninja Forms has an advance date picker option I am not familiar with it but here is the link看起来 Ninja Forms 有一个提前日期选择器选项我不熟悉但这里是链接

NOW I don't know the exact Ninja Forms syntax but this should jolt your brain to get started.现在我不知道确切的 Ninja Forms 语法,但这应该会让你的大脑开始震动。 Other wise you can create a small custom WP-plugin using a add_filter() and function like add_filter()您可以使用add_filter()和类似的function创建一个小的自定义WP-plugin

<?php
  
  add_filter( 'ninja_form_date_limt'  );
  
  function ninja_form_date_limt() {
      wp_enqueue_script( 
        'ninja_form_date_limt', 
        plugin_dir_url( __FILE__ ) . 'script.js', 
        array( 'jquery' ), 
        false, 
        true 
      );
  }

This calls on a JQuery or JavaScript function in your theme/js/script.js file or wherever you keep custom JS Which could will could use something like this.这会调用theme/js/script.js文件中的JQueryJavaScript函数,或者您保留自定义 JS 的任何地方,这可以使用这样的东西。

var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
dateObject.pikaday.setMinDate(tomorrow); 

Found a solution to this by combining a few things I found across the web while trying to solve this problem.通过结合我在网络上找到的一些东西来解决这个问题,同时试图解决这个问题。

Simply add this code to any page where you have a date picker where you want to restrict past dates.只需将此代码添加到您想要限制过去日期的日期选择器的任何页面。 This one also restricts the current day so they have to pick starting tomorrow.这也限制了当天,所以他们必须从明天开始选择。

<script>
jQuery(document).ready( function( $ ) {
var customDatePicker = Marionette.Object.extend( {
initialize: function() {

this.listenTo( Backbone.Radio.channel( 'flatpickr' ), 'init', this.modifyDatepicker );
},
modifyDatepicker: function( dateObject, fieldModel ) {
var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
dateObject.set("minDate", tomorrow );
}
});


new customDatePicker();
} );
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从当前日期禁用引导日期选择器以前的日期以及如何在 90 天日期之后限制或禁用日期选择器 - How to disabled bootstrap date picker previous dates from current date and how to restrict or disabled after 90 day dates form date picker 过去的日期没有隐藏在日期选择器中? - past dates are not hiding in date picker? 如何在引导程序日期选择器中显示过去的日期以供选择? - How to show past dates for selection in bootstrap date picker? 如何在javascript / jquery中的日期选择器中禁用日历中的过去日期? - How to disable past dates in calendar in date-picker in javascript/jquery? 在引导日期选择器中禁用过去的日期 - Disable past dates in bootstrap date picker 如何在 html5 输入类型 Date 中限制过去的日期 - How do I restrict past dates in html5 input type Date 如何在日期选择器上禁用过去的日期 - how to disable past date on date picker 如何在react-bootstrap-date-picker节点模块上禁用react js的过去和今天的日期? - how to disable past and today dates on react-bootstrap-date-picker node module for react js? 如何在日期选择器上禁用过去的日期。尝试了stackoverflow提供的所有解决方案 - How to disable the past dates on the date picker .Tried all solutions provided on stackoverflow ACF 日期选择器从前端删除过去的日期 - ACF Date picker remove past dates from front end
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM