Jquery UI datepicker implementation using text_field_tag in form_tag using
Rails
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) 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.
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>
Current JQuery code (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' });
});
});
My need is to include a specific datepicker for EACH form when a specific
button is clicked. i dont what im doing above in the jquery portion of the
code is correct? I also need to store the date entered by the user into
another object(variable?) so for each form I would get multiple objects
for storing.
Can someone please guide me with this? Thanks
No comments:
Post a Comment