How to submit multiple values from a select2 dropdown in html form - jquery-select2

Context: This contains 1 select2 dropdown with the ability to select multiple options
<div class="form-group" id="mediaBox" >
<label for="i">
Media Type
</label>
<select class="form-control" name="mediatype" style="width: 100%;" multiple="multiple" id="i">
<option>Original</option>
<option>Videogame</option>
<option>Comic and/or Manga</option>
<option>TV</option>
<option>Movie</option>
<option>Novel and Book</option>
</select>
</div>
Pictures of problem(Visual representation of the problem):
Picture 1(Second select2 dropdown):
Output:
Problem:
When I submit a form with multiple values from a select2 dropdown(I have 1 select2 dropdowns in this form that allows me to select multiple values) they each submit only one value I selected and not all of them for the mediatype variable. Can you help me solve this problem? Modify any html code if necessary.

Related

How to change " asp-action=" with your selected Viewbag .Net Core 2.0

I am trying to change the "asp-action= ", unfortunately I could not find anything on the internet...
Currently I am working with a ViewBag where I can select a value from that list.
What I want is: I want to put that selected value from the ViewBag in the "asp-action= ( here ) "
Image of my index
Image of my Post method
<form method="post" enctype="multipart/form-data" asp-controller="Parser" asp-action= "PostDrone">
<div class="col-md-10">
<p>Upload one or more files using this form:</p>
<select asp-items="#(new SelectList(#ViewBag.listofitems ))"></select>
<input type="file" name="files" multiple />
</div>
</div>
<div class="form-group">
<div class="col-md-10">
<input type="submit" value="Upload" />
</div>
</div>
For example:
I want the "asp-action=" have the string value "PostSchoen" if I selected PostSchoen from the viewbag selectlist
I hope it is understandable what i said
What you wants to do it should doing by client side development with JS
But you have three ways:
1) You can change it by using JS
here an example with Jquery
need add it to onReady function this will change action to option val
<script>
$(function() {
$("select").change(function (){
//set form action to option val or get to whatever you need
$(this).closest("form").attr("action",$(this).val());
});
});
</script>
2) Send data to one contoller method then switch it by your select or other options
change in view
<select name="typeOfUploading" asp-items="#(new
SelectList(#ViewBag.listofitems ))"></select>
change in controller
PostDrone(List<IFromFile> files, string typeOfUploading)
{
//and use typeOfUploading this will be selected value from your select list
}
3) Firstly provide for user this data send choise, that generate him correct view with needed action

How to bind data with select2 using ng-model?

I've set branchInfo.share_product=['X1','S1'] in js, and I want to use below code to bind the selected options with ['X1','S1'].
<select ui-select2 id="share_product_edit" class="form-control" multiple="multiple" tabindex="-1" ng-model="branchInfo.share_product">
<option ng-repeat="project in products" value="{{project.project}}">{{project.project}}</option>
</select>
What I want to achieve is:
But it shows like (just show "placeholder" value):

Render selectManyCheckbox without HTML table

is there a way to remove the table out of rendered html that is created by the h:selectManyCheckbox tag in server faces?
I am using twitter bootstrap and i placed the checkboxes inside a dropdown menu:
<ul class="dropdown-menu dropdown-menu-form">
<li><label class="checkbox"> <input type="checkbox" />
Activated
</label></li>
<li><label class="checkbox"> <input type="checkbox" />
Deactivated
</label></li>
</ul>
So the generated html table destroys the layout ...
You could just render a bunch of <h:outputLabel><h:selectBooleanCheckbox> inside <ui:repeat>. This way you've markup freedom. You'll only need to alter the model from e.g. List<T> to Map<T, Boolean> to represent the checked values and then loop over the map afterwards to collect checked ones.
A ready-to-use component is Tomahawk's <t:selectManyCheckbox> which has an additional layout attribute value of spread.

Rails - Submit Values based on Multiple Selection and Text Field

I'm still new in Rails. I'm trying to have a page where a user can select multiple items from a list then add some description into a text field. And at the end, the user should submit this information. How can I retrieve submitted data?
Any help would be greatly appreciated.
Thanks!
Here's the code for now:
<select multiple >
<option>Table</option>
<option>Door</option>
</select>
<br><br><br>
<select multiple >
<option>Blue</option>
<option>Red</option>
</select>
<input type="text" id="post_user" name="post" size="20" value="" />
All the form (POST) data can be found in the params hash. See attached links for details:
http://guides.rubyonrails.org/action_controller_overview.html#hash-and-array-parameters
Rails params explained?

select checkbox with hidden input type

Folks,
I am using watir-webdriver, I have a piece in my HTML DOM which gets generated on the fly when I enter some credentials, this piece has a bunch of checkboxes, the number of checkboxes vary, I have to select one checkbox, below is an example of this, here I want to select the second checkbox(the one that has value "BS" for the input type hidden but the value for input type checkbox is same for all):
<li class="dir">
<input type="checkbox" value="1" onclick="$(this).next('.should_destroy').value = (this.checked?0:1)" name="should_not_destroy">
<input class="should_destroy" type="hidden" value="1" name="import[dir_attributes][][should_destroy]">
<input type="hidden" value="" name="import[dir_attributes][][id]">
<input type="hidden" value="Automation" name="import[dir_attributes][][path]">
<span class="dir_mode">Include</span>
Automation
</li>
<li class="dir">
<input type="checkbox" value="1" onclick="$(this).next('.should_destroy').value = (this.checked?0:1)" name="should_not_destroy">
<input class="should_destroy" type="hidden" value="1" name="import[dir_attributes][][should_destroy]">
<input type="hidden" value="" name="import[dir_attributes][][id]">
<input type="hidden" value="BS" name="import[dir_attributes][][path]">
<span class="dir_mode">Include</span>
BS
</li>
I may be able to do this with XPATH, but wanted to try a non XPATH solution. The input type hidden has the appropriate value that I need, for example above the second checkbox has value "BS" for input type hidden. I tried to use the hidden method like this:
h = ##browser.hidden(:value, "BS")
h.select
But I dont know what to do after this. I am trying to select the checkbox based on the value of the hidden element. Any feedback is much appreciated.
I would suggest using the visible elements instead. I think it makes it easier to read the test and seems more stable.
Try:
##browser.li(:class => 'dir', :text => /BS/).checkbox.set
Here we go, I think this will do it
Since you have to select the checkbox based on the hidden, you're going to have to go up a level to the containing li, then drill down to the checkbox
#browser.hidden(value: 'BS').parent.checkboxes.first.set

Resources