ruby on rails - Bootstrap datepicker is appending one by one for 2 fields at a time -
in rails 3.2.9, using bootstrap's datepicker display date. in single form, need display datepicker 2 fields. if click first field datepicker popup. after if click 'tab' button popup second field's datepicker appending first datepicker. need display 1 datepicker @ time particular field's onclick. if click 'tab' button first field's datepicker should hidden , second field's datepicker should popup.
javascript below
function currentdatepicker(id){ var nowtemp = new date(); var = new date(nowtemp.getfullyear(), nowtemp.getmonth(), nowtemp.getdate(), 0, 0, 0, 0); $('#' + id).datepicker({ format: "yyyy-mm-dd", onrender: function(date) { return date.valueof() < now.valueof() ? 'disabled' : ''; } }); }
in views,
<%= f.input :start_date, :as=>:string, :label =>"start date", :required => false, :input_html=>{:readonly=>true, :value=>@user.start_date.blank? ? "" : @user.start_date} %> <%= f.input :end_date, :as=>:string, :label =>"end date", :required =>false, :input_html=>{:readonly=>true, :value=>@user.end_date.blank? ? "" : @user.end_date} %> <script type="text/javascript"> currentdatepicker('user_start_date'); currentdatepicker('user_end_date'); </script> 
above have added image more information. please me solve issue.
you can use different ids date picker , use event handling on ids. hide manualy first datepicker when clicked on 2nd datepicker. or use autoclose attribute of datepicker. $('#from').datepicker( { autoclose: true, startdate: today.getdate.tostring() } ); $('#to').datepicker( { autoclose: true, startdate: today.getdate.tostring() });
Comments
Post a Comment