简体   繁体   English

如何设置日期选择器以仅显示特定日期之后的日期

[英]How could I set my datepicker to only show dates after a certain date

Question is I have a two date pickers one is for leave_start and the other is for leave_end. 问题是我有两个日期选择器,一个用于leaves_start,另一个用于leave_end。 If someone chooses "YES" for future text_field I would like the datepicker's to then only show dates after the persons anniversary date. 如果有人为将来的text_field选择“是”,那么我希望日期选择器仅显示人员周年纪念日之后的日期。 the one problem I might run into is the the employees anniversary date will be when they where hired so I'm not sure how I could use just the month and day of there anniversary date to only show dates for this year after their anniversary date.. 我可能会遇到的一个问题是员工的周年纪念日将是他们被录用的时间,所以我不确定如何仅使用周年纪念日的月份和日期来仅显示其周年纪念日之后的这一年的日期。 。

So for example my name is Joe Smith and I choose a future request as "YES" and my anniversary date is 02/14/12. 例如,我叫乔·史密斯,我选择将来的请求为“是”,我的周年纪念日为02/14/12。 I want my leave_start leave_end datepickers to only show dates after 2/14 for this year. 我希望我的Leave_start Leave_end日期选择器仅显示今年2/14之后的日期。 Is this possible to do? 这可能吗? any help would be greatly appreciated!!!! 任何帮助将不胜感激!!!!

Basically I just don't want people picking a future request and being able to pick days before their anniversary date. 基本上,我只是不希望人们选择将来的请求并能够选择周年纪念日之前的几天。

Let me know if anyone will need more information this is what I have so far. 让我知道是否有人需要更多信息,这是我到目前为止所拥有的。 Any help would be greatly appreciated!!!! 任何帮助将不胜感激!!!!

Here are my datepickers in my entry.js.coffee 这是我的entry.js.coffee中的日期选择器

jQuery ->

 $('#leave_start').datepicker({minDate: 0, beforeShowDay: $.datepicker.noWeekends });


 $('#leave_end').datepicker({minDate: 0, beforeShowDay: $.datepicker.noWeekends });

Here is my view 这是我的看法

=simple_form_for @entry, :url => url_for(:controller => 'entry', :action 


%td.lt= f.error :range_days, :class => 'er'


%table.table.table-bordered.table-striped{:style => 'table-layout:fixed; width:100% !important;'}
  %th.lt Indirect Code:
  %td.lt= f.input_field :indirect_id, :as => :select, :id => 'indirect_id', :label => false, :collection => ['PD', 'VAC', 'ABS'], :hint => "If you choose ABS(this is considered an unpaid absence)"
  %td.lt= f.text_field :sick_day, :id => 'sick_day', :label => "This is for if you feel the need to comment on your unpaid request", :placeholder => 'Optional Comment', :input_html => {:value => ''}
  %td.lt= f.error :indirect_id, :class => 'er'

%table.table.table-bordered.table-striped{:style => 'table-layout:fixed; width:100% !important;'}
  %th.lt Will This Request be after your anniversary date?:
  %td.lt= f.input_field :future, :as => :select, :id => 'future', :label => false, :collection => ["YES", "NO"]
  %td.lt= f.error :future, :class => 'er'

%table.table.table-bordered.table-striped{:style => 'table-layout:fixed; width:100% !important;'}
  %th.lt Leave Start:
  %td.lt= f.text_field :leave_start,  :label => false, :id => 'leave_start', :input_html => {:value => ''}
  %td.lt= f.error :leave_start, :class => 'er'

%table.table.table-bordered.table-striped{:style => 'table-layout:fixed; width:100% !important;'}
  %th.lt Leave End:
  %td.lt= f.text_field :leave_end,  :label => false, :id => 'leave_end', :input_html => {:value => ''}
  %td.lt= f.error :leave_end, :class => 'er'


%td.lt= f.text_field :range_days, :label => false, :id => 'range_days', :input_html => {:value => ''}
%td.lt= f.text_field :full_range, :label => false, :id => 'gdates', :input_html => {:value => ''}


%table.table.table-bordered.table-striped{:style => 'table-layout:fixed; width:100% !important;'}
= f.button :submit, "Submit", :class => 'customSub'

Here is my model for the person's anniversary date 这是我这个人的周年纪念日的模特

class Empcomp < ActiveRecord::Base

  establish_connection :vdev

  self.table_name = 'empcomp'

  belongs_to :entry

end

And this is my entry controller for new and create 这是我用于新建和创建的入口控制器

  def new
    @entry = Entry.new
    @empaccrl = Empaccrl.where("person_id = ? and is_active = 'Y'", current_user.person_id)
    @empcomp = Empcomp.where("person_id = ?", current_user.person_id)
    respond_to do |format|

      format.html# new.html.haml
      format.xml { render :xml => @entry }
    end
  end


  def create
    params.permit!
    @entry = Entry.new(params[:entry])
    @entry.t_d
    @entry.day_hours
    @entry.current_user = current_user
    @empaccrl = Empaccrl.where("person_id = ? and is_active = 'Y'", current_user.person_id)
    @empcomp = Empcomp.where("person_id = ?", current_user.person_id)
    # send my email
    respond_to do |format|

      if @entry.save
        if current_user.email.nil?
          format.html { redirect_to(entry_path( @entry ), :notice => 'Entry successfully created, but you will not recieve any notifications, because you email is blank!') }
          format.xml { render :xml => @entry, :status => :created, :location => @entry }
        else
          EntryMailer.submit_for_approval(@entry).deliver
          format.html { redirect_to(entry_path( @entry ), :notice => 'Entry successfully created.') }
          format.xml { render :xml => @entry, :status => :created, :location => @entry }
        end
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @entry.errors, :status => :unprocessable_entity }
      end
    end
  end

Something like this is how I would like it to work but i cant get the anniversary date from my model. 这样的事情是我希望它能起作用的方式,但是我无法从我的模型中获得周年纪念日。 this date will be different so I cant set it as a static date 这个日期会有所不同,所以我无法将其设置为静态日期

$(document).ready(function(){
 $('#future').click(function() {
    var selected = $(this).val();
    if (selected == 'YES') {
     $('#leave_start').datepicker({minDate: '#anviersary_date', beforeShowDay: $.datepicker.noWeekends });
    } else {
     $('#leave_start').datepicker({minDate: 0, beforeShowDay: $.datepicker.noWeekends });
    }
  });
 });

That's why you have the minDate and maxDate . 这就是为什么要使用minDatemaxDate的原因

On the initializer: 在初始化程序上:

$( ".selector" ).datepicker({
  minDate: new Date(2007, 1 - 1, 1)
});

Setting after initialized: 初始化后的设置:

$( ".selector" ).datepicker( "option", "minDate", new Date(2007, 1 - 1, 1) );

You don't need to post all your code here. 您无需在此处发布所有代码。 Be specific. 请明确点。 :) :)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM