bootstrap typehead dropdown doesn't expand over bootstrap collapse - typeahead

So I have bootstrap collapse and inside it I have tabs, and inside one of the tabs I have a form with text_field that has bootstrap typeahead and the problem is that typeahead's dropdown dosn't expand over collapse.
that text_field with autocomplete is the last element in there.
here is the picture.
I want that dropdown expands below the collapse element (below the line on the picture)
EDIT:
Here is the haml for that view
- #i = 0
- #trainings.each do |training|
- #i = #i+1
.accordion#accordion2
.accordion-group
.accordion-heading
%a{:class => 'accordion-toggle', 'data-toggle' => 'collapse', :href => "#collapse#{#i}"}
= "Training #{#i}"
%div{:id => "collapse#{#i}", :class => 'accordion-body collapse'}
.accordion-inner
%pre= "Description: #{training.description}"
%ul.nav.nav-tabs#myTab
%li.active
%a{"data-toggle" => "tab", :href => "#planirano#{#i}"} Planirano
%li
%a{"data-toggle" => "tab", :href => "#napravljeno#{#i}"} Napravljeno
.tab-content
%div{:class => 'tab-pane active', :id => "planirano#{#i}"}
- training.exercises.each do |exercise|
%pre= "#{exercise.element.name} | #{exercise.description} | #{exercise.number_of_series}"
= form_for :training_exercise, :url => training_exercises_path(:training => training.id), remote: true, html: {:class => 'form-inline'} do |f|
= f.label :exercise
= f.text_field :exercise, :id => 'add_training_exercise'
= f.button :Add, :class => 'btn'
%div{:class => 'tab-pane', :id => "napravljeno#{#i}"} to sam napravio
f.text_ifeld :exercise, :id => 'add_training_exercise' is the field with autocomplete I am asking about.
EDIT:
and here is the rendered HTML

I somehow find the answer on stack overflow the solution is
.accordion-body.in { overflow:visible; }
It is from here.
I am sorry for asking question that already has the answer but I really was not able to find it because I didn't guess the right word for searching.

Applying the following css works only partially, accordion-body.in { overflow:visible; }, since it only displays the overflow of the "slice" that is being expanded. You'd need to apply it to the parent as well. In addition the above css affects the expand/collapse effect; i.e. the content of what is being shown get's displayed over the accordion, versus gradually being shown. A solution I tried is to:
1. Apply the overflow:visible only to the parent, i.e. #myAccordion { overflow:visible } AND
2. Apply overflow:visible only to the "slice" being opened when it is needed (on open), and removing it on close, like so:
$("#myAccordion").collapse();
// Here, we are attaching event handlers to the accordion "slice" body so that we can update it's overflow when opened AND when it's about to be closed.
$("#myAccordion .accordion-body").on("shown", function () {
$(this).css("overflow", "visible");
});
$("#myAccordion .accordion-body").on("hide", function () {
$(this).css("overflow", "hidden");
});

This worked for me since my typeahead is in a navbar
.navbar-collapse.in{
/*allows typeahead to overflow nav bar during collapse*/
overflow-y:initial !important;
}

Related

Ruby on Rails - Selected values are not working as expected in multiple: true (simple_form)

In my form, I have an f.select with multiple: true, but select doesn't work if it's not hardcoded in.
This is my form in new view:
= f.select :os, get_uniq_objects(:os), {}, {multiple: true }
My helper
def get_uniq_objects(obj)
somethings.pluck(obj).uniq
end
My controller
def campaign_params
params.require(:something).permit(os:[])
end
In new view, when OSs are selected, the result would saved as ['Linux', 'Windows'] so in my edit view I do as below but nothing gets selected:
= f.select :os, options_for_select(get_uniq_objects(:os), #something.os), {}, { multiple: true}
BUT if I hardcode them as below, everything works fine. I've even double checked what #something.os is by adding it to my view and its exactly like the hardcoded code.
= f.select :os, options_for_select(get_uniq_objects(:os), ['Linux', 'Windows']), {}, { multiple: true}
I'm not sure what I've done wrong here. Any help is appreciated and thanks in advance!
Taking a closer look into what value f.select got, helped me this solve this issue.
Value that was pass to it was as follow:
["Linux", "Windows"]
But for some reason, f.select got this array (with backslashes):
[\"Linux\", \"Windows\"]
This is my solution. In my model I did a gsub to change the saving values to string from an array:
before_save do
self.os_name.gsub!(/[\[\]\"]/, "") if attribute_present?("os_name")
end
so ["Linux", "Windows"], would become Linux, Windows
and I changed my f.select to following:
= f.select :os, options_for_select(get_uniq_objects(:os), #something.os.split(/\W+/)), {}, { multiple: true}
I did .split(/\W+/) to change the string to an array that f.select would accept.

How to display current_admin_user's name in navigation header?

Construction like:
menu.add :label => current_admin_user.full_name do |submenu|
menus.each do |m|
submenu.add :label => m['name'],
:url => "/admin/change/#{m['id']}",
:html_options => {:style => 'float:left;'},
:if => proc { current_admin_user.role?('super_admin') }
end
end
Doesn't work in 1.0pre+ anymore. There is no current_admin_user in the scope. But in the logs i see the request that fetches admin user before a menu getting added.
SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 6 ORDER BY `admin_users`.`id` ASC LIMIT 1
Any chance to deal with it?
It is still possible to use, i only needed to pass id of a menu
menu.add id: 'user_name' label: -> { current_admin_user.full_name } do |submenu|

Foundation 6 Multiple Accordions, how to have only one accordion expanded at once

I am using Foundation 6's Accordion feature and have three separate accordions on one page. By default, within a single accordion, you can only have one content expanded at a time. However, I want to have only one content open at a time for all accordions on the entire page.
I'm pretty sure I can accomplish this using their methods, specifically the "Up" method, however I cannot find any working examples and their documentation is pretty sparse. This is all they provide:
up
$('#element').foundation('up', $target);
Closes the tab defined by $target.
http://foundation.zurb.com/sites/docs/accordion.html
I am not really sure where to go from here.. so far this is what I have:
JS:
$(".accordion-title").click(function(e) {
//Not sure what to do with this
$('#element').foundation('up', $target);
});
HAML:
%ul.accordion#accordion-1{:'data-accordion' => "", :'data-allow-all-closed' => "true"}
%li.accordion-item
%a.accordion-title
Title 1
.accordion-content{:'data-tab-content' => ""}
Content 1
%li.accordion-item
%a.accordion-title
Title 2
.accordion-content{:'data-tab-content' => ""}
Content 2
%ul.accordion#accordion-2{:'data-accordion' => "", :'data-allow-all-closed' => "true"}
%li.accordion-item
%a.accordion-title
Title 1
.accordion-content{:'data-tab-content' => ""}
Content 1
%li.accordion-item
%a.accordion-title
Title 2
.accordion-content{:'data-tab-content' => ""}
Content 2
%ul.accordion#accordion-3{:'data-accordion' => "", :'data-allow-all-closed' => "true"}
%li.accordion-item
%a.accordion-title
Title 1
.accordion-content{:'data-tab-content' => ""}
Content 1
%li.accordion-item
%a.accordion-title
Title 2
.accordion-content{:'data-tab-content' => ""}
Content 2
I found the solution to my question in case anyone else is stuck:
$(".accordion-title").click(function(e) {
$('.accordion').foundation('up', $('.accordion .accordion-item.is-active .accordion-content'));
});
I couldn't get alexandraleigh's answer to work, it was also closing the accordion I had just clicked to open.
The following is what I wrote in the end. It works on accordions set with either data-multi-expand="true" or data-multi-expand="false"
/**
* on accordion section click
*/
$('.accordion-title').on('mouseup', function (e) {
var $accordionItem = $(this).parent(),
//is the section hidden? if the section is not yet visible, the click is to open it
opening = ($accordionItem.find('.accordion-content:hidden').length === 1);
//
if (opening) {
//the accordion that has just been clicked
var $currentAccordion = $accordionItem.parent();
//close all other accodions
$('.accordion').each(function () {
var $acc = $(this);
//ignore the accordion that was just clicked
if ($acc[0] !== $currentAccordion[0]) {
//find any open sections
var $openSections = $acc.find('.accordion-item.is-active .accordion-content');
//
$openSections.each(function (i, section) {
//close them
$acc.foundation('up', $(section));
});
}
});
}
});
I couldn't get r8n5n's answer to work - perhaps because of Foundation's updates since. But I managed to get it working with the following on v6.3.0..
jQuery('.accordion-title').on('mouseup', function (e) {
jQuery('.accordion').each(function () {
jQuery(this).foundation('up', jQuery('.accordion-content'));
});
});
I had some minds on a previous answers
if you have 2 accordion just add classname to them. For example class="accordion accordion-first" and class="accordion accordion-second".
//close active item on second accordion when click on first accordion
$(".accordion-first .accordion-title").click(function(e) {
$('.accordion').foundation('up', $('.accordion-second .accordion-item.is-active .accordion-content'));
});
//close active item on first accordion when click on second accordion
$(".accordion-second .accordion-title").click(function(e) {
$('.accordion').foundation('up', $('.accordion-first .accordion-item.is-active .accordion-content'));
});

how to edit menu bar in active admin? - change the language. Rails

I'm using Active Admin with i18n. Everything works but if i want to change language I need to do that by hand - changing site address :-(... How to add buttons in navigate bar with models names? It could be another place but good for that - accessible.
You can set a default locale in a before filter by adding the following lines to application_controller.rb:
before_filter :set_locale
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
def default_url_options(options={})
{ :locale => I18n.locale }
end
Add a menu for selecting languages in active_admin.rb:
config.namespace :admin do |admin|
admin.build_menu :utility_navigation do |menu|
menu.add :label => "Languages" do |lang|
lang.add :label => "English",:url => proc { url_for(:locale => 'en') }, id: 'i18n-en', :priority => 1
lang.add :label => "Mexican",:url => proc { url_for(:locale => 'es') }, id: 'i18n-es', :priority => 2
end
menu.add :label => proc { display_name current_active_admin_user },
:url => '#',
:id => 'current_user',
:if => proc { current_active_admin_user? }
admin.add_logout_button_to_menu menu
end
end
You can set the default locale in application.rb:
config.before_configuration do
I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s]
I18n.default_locale = :en
I18n.reload!
end

Why am I getting "Can't mass-assign protected attributes" after adding a field to a product on spree?

I'm trying to add a field to products on spree which is just a checkbox which is just ment to mark products if they are for sale or they're internal products.
I've added the migration and finally figured out how to add the checkbox on the form, but when I click Update I get Can't mass-assign protected attributes: for_sale
This is the migration
class AddProductForSaleField < ActiveRecord::Migration
def up
add_column :spree_products, :for_sale, :boolean
end
def down
remove_column :spree_products, :for_sale
end
end
Here's the field being added
Deface::Override.new(:virtual_path => "spree/admin/products/_form",
:name => "for_sale",
:insert_before => "code[erb-silent]:contains('track_inventory_levels')",
:partial => "spree/admin/products/for_sale")
And this is the partial
<%= f.field_container :for_sale do %>
<%= f.label :for_sale, t(:for_sale) %>
<%= f.check_box :for_sale, { :checked => true } %>
<% end %>
got it, was missing the model part
Spree::Product.class_eval do
attr_accessible :for_sale
end
Mass Assignment is the name Rails gives to the act of constructing your object with a parameters hash. It is "mass assignment" in that you are assigning multiple values to attributes via a single assignment operator.
The following snippets perform mass assignment of the name and topic attribute of the Post model:
Post.new(:name => "John", :topic => "Something")
Post.create(:name => "John", :topic => "Something")
Post.update_attributes(:name => "John", :topic => "Something")
In order for this to work, your model must allow mass assignments for each attribute in the hash you're passing in.
There are two situations in which this will fail:
You have an attr_accessible declaration which does not include :name
You have an attr_protected which does include :name
It recently became the default that attributes had to be manually white-listed via a attr_accessible in order for mass assignment to succeed. Prior to this, the default was for attributes to be assignable unless they were explicitly black-listed attr_protected or any other attribute was white-listed with attr_acessible.
If it's a permission issue then you can add :
Spree::Product.class_eval do
attr_accessible :variable_1, :variable_2 :as => [:default, :product]
end
Marking it as default for a specific model, will remove the mass-assignment warning message !