Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for comma separated string data? #4905

Closed
burzum opened this issue May 16, 2017 · 1 comment
Closed

Example for comma separated string data? #4905

burzum opened this issue May 16, 2017 · 1 comment

Comments

@burzum
Copy link

burzum commented May 16, 2017

Can we please get a working example for comma separated string data?

The announcement here says the use of the hidden field for that task is deprecated but the documentation doesn't really explain how else you can do it now.

I still need to use the hidden field to get the data.

		var clients = ($('#clients').val().split(','));
		for (var i = 0; i < clients.length; i++) {
			var client = clients[i].trim();
			if (client.length === 0) {
				continue;
			}
			$('#clients-select').append('<option selected="selected" value="' + client + '">' + client + '</option>');
		}
		$('#clients-select').select2({
			tags: true,
			multiple: true,
			tokenSeparators: [','],
			minimumResultsForSearch: Infinity
		});
<div class="col-md-6">
	<input type="hidden" name="clients_data" id="clients" value="test3, test4">
	<div class="form-group select float-label-control">
		<input type="hidden" name="clients" value="" class="empty">
		<select name="clients[]" multiple="" id="clients-select" class="form-control select2-hidden-accessible" tabindex="-1" aria-hidden="true">
			<option selected="selected" value="test3">test3</option>
			<option selected="selected" value="test4">test4</option>
		</select>
		<span class="select2 select2-container select2-container--default select2-container--focus" dir="ltr" style="width: 720px;">
			<span class="selection">
				<span class="select2-selection select2-selection--multiple" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="-1">
					<ul class="select2-selection__rendered">
						<li class="select2-selection__choice" title="test3"><span class="select2-selection__choice__remove" role="presentation">×</span>test3</li>
						<li class="select2-selection__choice" title="test4"><span class="select2-selection__choice__remove" role="presentation">×</span>test4</li>
						<li class="select2-search select2-search--inline"><input class="select2-search__field" type="search" tabindex="0" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" role="textbox" aria-autocomplete="list" placeholder="" style="width: 0.75em;"></li>
					</ul>
				</span>
			</span>
			<span class="dropdown-wrapper" aria-hidden="true"></span>
		</span>
	</div>
</div>
@pedrofurtado
Copy link
Contributor

Please, send us a JSFiddle example code simulating this scenario (with runnable code and steps described there, to allow us to follow this steps and check the situation). It is much more easy to understand and help to provide some solution or workaround. You are free to reopen when the JSFiddle are done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants