Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add datetimepicker to a textbox?

I am having a text_field_tag in rails.

<%=text_field_tag 'promocode_expiration','',class: "promoExp form-control",id: "datetimepicker1",size: 10%>

On click of this text_field i wish to open a datetimepicker, to add date to the field.

How can i achieve it? Can anyone help please? thank you in advance.

like image 499
Vishal Avatar asked Sep 11 '25 07:09

Vishal


1 Answers

You need to add this two line :

gem 'momentjs-rails', '>= 2.9.0'
gem 'bootstrap3-datetimepicker-rails', '~> 4.17.37'

Then, You need to do :

$ bundle

Then, Add the following to your JavaScript manifest file (application.js):

//= require moment
//= require bootstrap-datetimepicker

And, modify your application.css and add :

*= require bootstrap
*= require bootstrap-datetimepicker

And Lastly, In your view file :

<div class='input-group date' id='datetimepicker1'>
  <input type='text' class="form-control" />
    <span class="input-group-addon">
      <span class="glyphicon glyphicon-calendar"></span>
    </span>
</div>
<script type="text/javascript">
  $(function () {
    $('#datetimepicker1').datetimepicker();
  });
</script>

This had worked for me.

like image 133
Hardik Kanjariya ツ Avatar answered Sep 12 '25 20:09

Hardik Kanjariya ツ