1,105,578 Community Members

Jquery UI datepicker implementation in erb form in rails

orange88
Newbie Poster
1 post since Sep 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

QUESTION: My need is to include a specific datepicker for EACH form when a specific button is clicked. Im not sure whether what im doing below in the jquery portion of the code for the datepicker is correct? Can someone please guide me with this? Thanks

DETAILS: I am currently using a hidden form(hidden using css ===> display: none) for user input which displays on button click within table. I am trying to include a datepicker (using the jquery-ui-rails gem (gemfile)) in the text_field_tag of the form by specifying a class(datepicker) for use in the corresponding Jquery code. I am using Rails, Ruby, Jquery and HTML.

Current JQuery code in my application.js file (displays only the corresponding hidden 'td' element for that corresponding single button) including the datepicker:

      $(document).ready(function(){ 
      $( "button.edit_description" ).on( "click", function( event ) { 
      $(this).closest('td').find( "div.file_description_update" ).show(); 

      }); 
      $(function() {
      $('.datepicker').datepicker({ dateFormat: 'yy-mm-dd' });
      });

      });

I also have the following in my application.js :

        //= require jquery.ui.all
        //= require jquery.ui.datepicker

and also the following in my application.css.scss:

      *= require_self
      *= require_tree .
      *= require bootstrap-datepicker
      *= require jquery.ui.all

Code for View:

   <h2>Files</h2>
   <table class="table">
   <tr>
   <th>Filename</th>
   <th>Description</th>
   <th>Download Link</th>
   </tr>
   <% @files.each do |file| %>
   <% filename = file.split('/').last %>
   <% object = @bucket.objects[file] %>

   <tr>         
   <td><%= filename %></td>    

   <td>
   <div class="file_description"><%= object.metadata['description']%>    
   <button id     ="file3" type="button"  class= "btn btn-default   
    edit_description"   onclick="Window(this)">Edit</button>                      
   </div>

    <div id = file2 class="file_description_update" >
    <%= form_tag({:action => 'update_file_info'}, multipart: true) do %> 
    Update File Description: <%= text_area_tag :description %>
    <%= hidden_field_tag :s3_path, file %>  
    <%= hidden_field_tag :prefix, @prefix %>
     <%= text_field_tag 'data', nil, :class => 'datepicker' %>
    <%= submit_tag 'Submit' %> </td> <br />
    <% end %>
     </div>

    </td> 
LastMitch
Deleted Member
 
0
 

QUESTION: My need is to include a specific datepicker for EACH form when a specific button is clicked. Im not sure whether what im doing below in the jquery portion of the code for the datepicker is correct? Can someone please guide me with this? Thanks

Read this:

http://api.jqueryui.com/datepicker/

There are code that you can used. I assume you test out the datepicker before you implement on Ruby. I'm not very familiar with Ruby but know a little.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article