Sha256: 02fc2633fab0359910a33fb6031eba50ff506da23cd1b2b2f7a82a902cf0cd91
Contents?: true
Size: 1.44 KB
Versions: 4
Compression:
Stored size: 1.44 KB
Contents
$(document).ready( function() { $('.selectized').each( function() { var remote = $(this).attr( 'data-opt-remote' ) ? $(this).attr( 'data-opt-remote' ) : ''; var field_text = $(this).attr( 'data-opt-text' ) ? $(this).attr( 'data-opt-text' ) : 'name'; var field_value = $(this).attr( 'data-opt-value' ) ? $(this).attr( 'data-opt-value' ) : 'id'; var opts = { closeAfterSelect: true, create: false, hideSelected: true, labelField: field_text, options: [], plugins: ['remove_button'], searchField: field_text, valueField: field_value }; if (!$(this).data('opts') ) { $.each( this.attributes, function( i, attr ) { if( attr.name.startsWith( 'data-opt-' ) ) { var name = attr.name.substr( 9 ); if( name != 'remote' && name != 'text' && name != 'value' ) opts[name] = ( attr.value == 'true' ) ? true : ( ( attr.value == 'false' ) ? false : attr.value ); } }); } else { opts = $.extend({}, opts, $(this).data('opts')); } opts['load'] = function( query, callback ) { if( !query.length ) return callback(); $.ajax({ url: remote + '?q[' + field_text + '_contains]=' + encodeURIComponent( query ), type: 'GET', error: function() { callback(); }, success: function(res) { callback( res.slice( 0, 10 ) ); } }); }; $(this).selectize( opts ); }); });
Version data entries
4 entries across 4 versions & 1 rubygems