Poors man autocomplete for the #authors_list
parent
395ab9bb40
commit
530156cce0
|
@ -14,4 +14,5 @@
|
|||
//= require turbolinks
|
||||
//= require nprogress
|
||||
//= require nprogress-turbolinks
|
||||
//= require mods
|
||||
//= require mods
|
||||
//= require_tree ./inputs
|
|
@ -0,0 +1,23 @@
|
|||
$(document).on 'page:change', ->
|
||||
$('.multi_datalist').each (i, el)->
|
||||
$el = $(el)
|
||||
$input = $el.find('input')
|
||||
$datalist = $el.find('datalist')
|
||||
|
||||
initialOptions = []
|
||||
initialOptionsValues = []
|
||||
for option in $datalist.children()
|
||||
initialOptions.push option
|
||||
initialOptionsValues.push option.value
|
||||
|
||||
separator = $input.attr('separator')
|
||||
separatorRegex = new RegExp(".*#{separator}\\s*")
|
||||
|
||||
$input.on 'textInput input change', (ev)->
|
||||
listPrepend = $input.val().match(separatorRegex)
|
||||
listPrepend = if listPrepend then listPrepend[0] else ''
|
||||
$datalist.remove()
|
||||
for option, i in initialOptions
|
||||
option.value = listPrepend + initialOptionsValues[i]
|
||||
$datalist.appendTo $el
|
||||
null
|
|
@ -58,6 +58,7 @@ class ModsController < ApplicationController
|
|||
|
||||
def new
|
||||
@mod = Mod.new
|
||||
@existing_authors_names = User.pluck(:name)
|
||||
mod_version = @mod.versions.build
|
||||
mod_file = mod_version.files.build
|
||||
|
||||
|
@ -87,6 +88,7 @@ class ModsController < ApplicationController
|
|||
|
||||
def edit
|
||||
@mod = Mod.find params[:id]
|
||||
@existing_authors_names = User.pluck(:name)
|
||||
render :new
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
class MultiDatalistInput < Formtastic::Inputs::DatalistInput
|
||||
include Formtastic::Inputs::Base::Placeholder
|
||||
|
||||
def input_html_options
|
||||
{
|
||||
separator: @options[:separator] || ','
|
||||
}.merge(super)
|
||||
end
|
||||
end
|
|
@ -13,7 +13,7 @@
|
|||
= f.input :categories, as: :categories_select
|
||||
= f.input :author_name if current_user.is_admin?
|
||||
= f.input :author if current_user.is_admin?
|
||||
= f.input :authors_list
|
||||
= f.input :authors_list, as: :multi_datalist, collection: @existing_authors_names, placeholder: @existing_authors_names.sample(4).push('etc').join(', ')
|
||||
= f.input :github
|
||||
= f.input :official_url
|
||||
= f.input :forum_url
|
||||
|
|
|
@ -68,4 +68,8 @@ en:
|
|||
forum_subforum_url: Big mods have their own subforum
|
||||
imgur: "For an individual picture, not and album"
|
||||
mod_file:
|
||||
download_url: "Please use this instead of the attachment when possible, specially for large files"
|
||||
download_url: "Please use this instead of the attachment when possible, specially for large files"
|
||||
|
||||
placeholders:
|
||||
mod:
|
||||
authors_list: 'Author1, Author2, Author3, etc'
|
Loading…
Reference in New Issue