bootstrap date picker rails not working - ruby-on-rails

read = ->
$('#date_picker').datepicker
$(document).ready read
$(document).on "page:load", read
This the code I am using the above is how I call the datepicker. I am using date picker rails gem. The below is the form code
= simple_form_for :due_on,:url=> admin_requests_path,:method => "get",html: {id: "due_on_filter"} do |f|
= f.input :mydate,:disabled => 'disable', :input_html => { :data => {:behaviour => :datepicker },id: "date_picker"}
I am not able to get it to work. There are no errors but datepicker just does not work.
This is my application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require jquery.ui.core
//= require jquery_nested_form
//= require dataTables/jquery.dataTables
//= require dataTables/jquery.dataTables.bootstrap3
//= require datatable_calls
//= require nprogress
//= require nprogress-turbolinks
//= require chosen-jquery
//= require chosen_calls
//= require filter_ajax_calls
//= require bootstrap-datepicker/core
//= require custom
HTML raw output of the form is:
<form accept-charset="UTF-8" action="/admin/requests" class="simple_form due_on" id="due_on_filter" method="get" novalidate="novalidate">
<div style="display:none"><input name="utf8" type="hidden" value="✓" /></div>
<div class="control-group string required due_on_mydate">
<label class="string required control-label" for="date_picker">
<abbr title="required">*</abbr> Mydate</label>
<div class="controls">
<input class="string required" data-behaviour="datepicker" id="date_picker" name="due_on[mydate]" type="text" />
</div>
</div>
</form>

you sure this js/coffee code works?
Could you try that please:
setInterval(function() {
$(function () {
var datepicker = $('#date_picker');
if(datepicker.length) {
datepicker.datepicker();
alert("found the element!");
} else {
alert("could not find element");
}
});
}, 4000);

Edit in your script as
$(function(){$("#datepicker").datepicker({
showbuttonPanel: true
});
});
and you need to require bootstrap and jquery-ui-1.10.4.custom files in both js & css application. Now implement the datepicker where ever you want using the datepicker id.

Related

Why bootstrap modal can't display on Rails 5?

1.code of index.html.erb:
<%= link_to 'Add release', new_release_articles_path, {:remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window'} %>
<div id="modal-window" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
<p>Hoc javascript</p>
code of controller:
def new_release
respond_to do |format|
format.html
format.js
end
end
code of new_release.js.erb
$('#modal-window').html("<%= j render 'blorgh/articles/new_release'%>");
$('#modal-window').modal();
code of new_release.html.erb
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
**here comes whatever you want to show!**
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
application.js
//= require rails-ujs
//= require jquery
//= require bootstrap
//= require jquery_ujs
//= require turbolinks
//= require_tree .
Result click link add release:
Look at this
//= require rails-ujs
//= require jquery
//= require bootstrap
//= require jquery_ujs
//= require turbolinks
//= require_tree .
You don't need rails-ujs if you use jquery_ujs so you can remove this //= require rails-ujs from here and follow the order
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require turbolinks
//= require_tree .
you can consider one rails-ujs or jquery_ujs, after changing this restart the server
Update from comment
Use tabindex="-1" to div modal window

Add autocomplete to the navigation bar in Rails Project

I'm running a Rails project which consists of Navgation bar on all the pages. I also have a input tag on the nav bar for searching purpose, but how to implement autocomplete in the particular search bar.
I tried using rails-jquery-autocomplete and implemented the way it asked but unfortunately it didn't worked for me. No search result are visible on screen or on console
brands_controller.rb
class Admin::BrandsController < Admin::AdminController
autocomplete :brand, :name
end
routes.rb
resources :brands, param: :uuid do
get :autocomplete_brand_name, :on => :collection
end
_navigationbar.html.erb
<form class="navbar-form pull-left" role="search">
<div class="form-group">
<input type="text" class="form-control search-bar" placeholder="Type here for search..." data-autocomplete="<%=autocomplete_brand_name_admin_brands_path%>">
</div>
</form>
Gemfile
gem 'rails', '~> 5.0.0'
gem 'rails-jquery-autocomplete'
gem 'jquery-rails'
application.js
//= require jquery
//= require jquery_ujs
//= require moltran/modernizr.min
//= require moltran/bootstrap.min
//= require tagsinput/jquery.tagsinput.min.js
//= require autocomplete-rails
Generated HTML:
<div class="form-group">
<input type="text" class="form-control search-bar" placeholder="Type here for search..." data-autocomplete="/admin/brands/autocomplete_brand_name">
</div>
You are missing //= require jquery-ui/autocomplete in application.js. Update application.js to
//= require jquery
//= require jquery_ujs
//= require moltran/modernizr.min
//= require moltran/bootstrap.min
//= require tagsinput/jquery.tagsinput.min.js
//= require jquery-ui/autocomplete
//= require autocomplete-rails
In your gemfile add
gem 'jquery-ui-rails'
Also replace input tag with
<%=autocomplete_field_tag 'search', '', autocomplete_brand_name_admin_brands_path %>

Bootstrap-select not expanding

I am facing problems with dropdown of selectpicker. I am not able to get the dropdown menu when i click on .
Following are my files:
View:
<div class="form-group set-up-down">
<%= f.label :pricing_style_id %><br>
<%= f.select 'pricing_style_id', options_from_collection_for_select(#labs_pricing_style, :id, :name),{:include_blank => '-Choose Starting Price Sheet-'},class:'selectpicker'%>
<p id="pricingstyleError" style="display: none; color: red;">Please enter a pricing style for this new pricesheet.</p>
</div>
application.js:
//= require jquery
//= require jquery_ujs
//= require jquery.turbolinks
//= require bootstrap-colorpicker.min
//= require bootstrap-datetimepicker.min
//= require bootstrap-select.min
//= require bootstrap-switch
//= require bootstrap-switch.min
//= require bootstrap-tagsinput
//= require bootstrap
//= require jquery-1.12.1.min
// require_tree .
application.css:
*= require_tree .
*= require_self
Any help will be appreciated. thank you in advance.

Owl Carousel Slider won't Display in Ruby on Rails App

I've been trying to implement the OwlCarousel image slider into my RoR app. The problem is that the slider doesn't seem to be called upon.
This is what it currently outputs (with two images) -
This is my current relevant code -
In application.js
//= require jquery
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require owl.carousel
//= require_tree .
In application.css.scss
/*
*= require owl.carousel
*= require owl.theme
*= require_tree .
*= require_self
*/
#import "bootstrap-sprockets";
#import "bootstrap";
In show.html.erb
<div>
<div class="col-xs-12 col-md-offset-2 col-md-6 project-right-panel">
<div id="owl-carousel">
<% #post_attachments.each do |p| %>
<%= image_tag p.avatar_url %>
<%= link_to "Edit Attachment", edit_post_attachment_path(p) %>
<% end %>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#owl-carousel").owlCarousel({
autoPlay: 3000,
item : 3,
itemsDesktop : [1119,3],
itemsDesktopSmall : [979, 3]
});
});
</script>
item : 3 should be items: 3. That might be it. Their demo also looks like they want you to wrap your images in a div with class item.

Javascript not working - changing image to text on click

I've asked a question recently on how to change 2 icons to text on click. The solution worked for a while, but now it's not working. Is there another way to do it or is the problem in the code? I face the problem with other scripts very often.
application.js
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require jquery.ui.all
//= require jquery.turbolinks
//= require jquery_nested_form
//= require_tree .
show.html.erb
<div class="thumbsup">
<%= link_to image_tag('othericons/thumbsup_off.PNG', height: '20', width: '20', like_post_comment_path(comment.post_id, comment), method: :put, :remote => true %>
</div>
<div class="thumbsdown">
<%= link_to image_tag('othericons/thumbsdown_off.PNG', height: '20', width: '20', dislike_post_comment_path(comment.post_id, comment), method: :put, :remote => true %>
</div>
html output
<div class="thumbsup">
<a data-method="put" data-remote="true" href="/posts/1/comments/4/like" rel="nofollow">
<img alt="Thumbsup off" height="21" src="/assets/othericons/thumbsup_off.PNG" width="20" />
</a>
</div>
<div class="thumbsdown">
<a data-method="put" data-remote="true" href="/posts/1/comments/4/dislike" rel="nofollow">
<img alt="Thumbsdown off" height="21" src="/assets/othericons/thumbsdown_off.PNG" width="20" />
</a>
</div>
icons.js
$('.thumbsdown a, .thumbsup a').on('click', function()
{
$('.thumbsdown').before('You voted')
$('.thumbsdown, .thumbsup').remove()
})
If it was working before, the problem is likely an issue with Turbolinks:
$(document).on("click", ".thumbsdown a, .thumbsup a", function() {
$('.thumbsdown').before('You voted')
$('.thumbsdown, .thumbsup').remove()
});

Resources