How do I change the delimiter separating the values selected in select2? I've tried tokenSeparators, but it doesn't seem to work for me.
Select2 Version 3.5.2
$(".product-autosuggest").select2({
placeholder: "Search",
tokenSeparators: [';'],
Related
As the title shows, I used the Select2 without any error. The component works properly when I enter characters for search. The problem is that, when I click to open drop-down list, an empty list is shown. I checked the styles and scripts' probable conflicts, and test a simple lite version of select2 without any extra library. Unfortunately, The problem remains.
The problem is originated from minimumInputLength configuration parameter. If you set this parameter, the drop-down-list will be empty until a search term character enters. I commented out the problematic line, and everything seems good now.
$("#itemsList").select2({
placeholder: "Select Item",
language: "en",
// minimumInputLength: 1,
data: s_data,
formatSelection: format_data,
formatResult: format_data
});
I'm trying to set tokenSeparators option using data-token-separators="[',']" but nothing happens, what is the right syntax to pass array of token separators in data attribute?
data-token-separators="[',']" is the correct way to do it. You may want to update to a newer version of Select2 as I found earlier versions were not handling this feature very well.
Recreate the select2 object with the updated settings.
So lets say your original separator was:
$(".js-example-tokenizer").select2({
tags: true,
tokenSeparators: [',', ' ']
})
Then it should look like:
$(".js-example-tokenizer").select2({
tags: true,
tokenSeparators: [',']
})
Visit select2 if you want more information.
My ransack form has a date to and from search using a datepicker for each. The search and results works great, however I would like to style the form fields so that when the results load, the datetime can be formated just to_date. I am unsure how to access the value used in the form. I could just use the value parameter and apply the styling, but I do not know the variable to use.
<%= f.text_field :order_date_lt, class: "", id: "datepicker1", value: ?????.to_date.strftime('%m-%d-%Y') %>
I found out that in this case #q.order_date_lt, if it is present, will be able to be formatted that way
Can some one suggest the best way for setting hint text(not default text) for a text field in Ruby on Rails. Currently I am using this:
<%= text_field_with_auto_complete
"customer",
:contact_person, {
:value => 'last, first',
:style => 'color:#aaa;width:11em;',
:onfocus => "if(this.getValue()=='last, first'){this.clear();this.style.color = '#000';}",
:onblur => "if(this.getValue()==''){this.setValue('last, first');this.style.color = #aaa';}"
} %>
The text field is attached to a model and in turn to a value in a database. Also, the same html that is used in index.html is also used in edit.html and hence when I try to edit the field, the default value shows up instead of the value from the database. What is the correct way to do this?
Note: I am not trying to set a default value but just a hint to what needs to be entered in the text box.
Thanks,
Raja Ram
I'd recommend using the HTML 5 placeholder attribute, and then using a jQuery plugin to make it work on older browsers (like this one, but there are many others on Google).
You can see this technique used in production here.
Try this jquery plugin
http://plugins.jquery.com/project/hint
or choose here:
http://plugins.jquery.com/plugin-tags/hint
For prototype
http://davidchambersdesign.com/autopopulating-input-fields-with-prototype/
I have a select table that is generated using
view :
<select id = "car_type", name="car_type">
<%= options_from_collection_for_select #cartype, 'id', 'name' %>
<select>
and in controller I have this
#cartype = Cartype.find(:all)
I need to get the current selection value, so I can generate a second select table based on the first option selection. I am aware that this can be done with observe_field, however, there is some problems with observe_field, so first I decided to use parameter passing.
Would appreciate for any hints
can anyone point out, how can I get the current selection value and pass the value?
As you can see in the Rails documentation for options_from_collection_for_select the last parameter is the selected value and should be an interger. E.g.
options_from_collection_for_select(#people, 'id', 'name', 1)