Standard dropdown:
<%= f.select :category_cont, @categories, :include_blank => true %>
Now, I want to be able not only to pick categories from dropdown menu but also add new category on the fly. Of course I can have <%= f.text_area :category %>
next to my dropdown menu but it does not seem to be very elegant. Is there any way to be able to chose values from the pull down menu but also to add new if required?
Check this Selectize.js
Search for "Single Item Select"
Check here when you choose option not exist it suggest to add it to options
app/javascript/application.js:
//= require_tree .
//= require selectize
$(function() {
$('#category-select').selectize({
create: true,
sortField: 'text'
});
});
application.css:
*= require selectize
*= require selectize.default
my form (view):
<%= f.select(
:category,
@categories,
{},
{id: 'category-select' }
) %>
did the trick.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.