how to change the height of select2? - jquery-select2

I tried many things to change the height of select2 but no success. Any help would be appreciated.
this is my code.
<select name="customer_id" class="form-control select2" #error('customer_id') is-invalid #enderror name="customer_id" value="{{ old('customer_id') }}" required autocomplete="customer_id">
<option selected>Select Customer to link Item</option>
#foreach ($customers as $customer)
<option value="{{ $customer->id }}">{{ $customer->customer_name }}</option>
#endforeach
</select>
this is the screenshot select boxes image
I checked this link and tried but it din't work.

Related

SOLVED - Select2 attr "selected" stop working when set false

The goal is to select users according to the option chosen in the first select.
It works fine the first time you select that type of user. But when I change the user type and go back to the previous one, it doesn't show the options in the select. But through the inspect element it appears that the option has the "selected" attribute
<label for="UserType" class="col-md-2 control-label">User Type nbsp;<span class="text-danger small">*</span></label> <div class="col-md-4">
<select class="select2_demo_1 form-control" id="UserType" name="UserType">
<option value='0' selected disabled hidden>-- Selecionar --</option>
<option value="1">Boss</option>
<option value="2">Admin</option>
<option value="3">User</option>
</select>
<label for="Users" class="col-md-2 control-label">Users <span class="text-danger small">*</span></label><div class="col-md-10">
<select id="Users" name="Users" class="select2_demo_1 form-control" multiple style="width:100%">
<option data-type='1' value="1" >User Boss</option>
<option data-type='2' value="2" >User Admin</option>
<option data-type='2' value="3" >User Admin 2</option>
<option data-type='3' value="4" >User</option>
</select>
$('#UserType').on('change', function() {
var UserType = $(this).val();
$("select#Users option:selected").attr("selected",false);
$("select#Users option[data-type="+ UserType +"]").attr("selected","selected");
$("#Users").select2();
});
$('#UserType').trigger('change');
------ Solution ------
Change the code segment
$("select#Users option:selected").attr("selected",false);
$("select#Users option[data-type="+ UserType +"]").attr("selected","selected");
$("#Users").select2();
by the following
$('#UserType').select2('destroy').find('option').prop('selected', false).end().select2();
$('#UserType').select2('destroy').find('option[data-type='+ UserType+']').prop('selected', 'selected').end().select2();
You may think to add selected="true" and then change it to false when you apply the function attr()

Getting selected item from ASP MVC3 drop down list

I am trying, without any luck, to use the selected item from a drop down list in the controller. I've stepped through the code and can see that each of the string values are "null" after they should be assigned.
Below is the code from the View
<span id="searchBox" class="boxMe" >
<select id="Table" title="Table" style="font-size:8pt;">
<option value="default">--Table Name--</option>
<option value="CE">CE</option>
<option value="PT">PT</option>
</select>
<select id="IssueType" style="font-size:8pt;">
<option value="default">--Issue Type--</option>
<option value="W">Warning</option>
<option value="E">Error</option>
</select>
<select id="Status" style="font-size:8pt;">
<option value="default">--Status Type--</option>
<option value="O">Open</option>
<option value="U">Under Review</option>
</select>
<input type="image" src="#Url.Content("~/Content/Images/Filter.bmp")" alt="Filter" style="padding-top: 0px;" />
</span>
And here is what I have in the controller. As this is a search filter I have this in the Index() method at the moment.
public ViewResult Index(FormCollection dropDownSelection)
{
string table = dropDownSelection["Table"];
string issue = dropDownSelection["IssueType"];
string status = dropDownSelection["Status"];
return View(db.FollowUpItems.ToList());
}
You should use the name attribute on your <select> tags, rather than id. The name is what is used as the key in the form post:
<select name="Table" title="Table" style="font-size:8pt;">
If you haven't already, you should also wrap your inputs in <form> tags:
<span ...>
<form method="post">
<!-- Inputs -->
</form>
</span>

placeholder not working in jquery mobile with select

http://jsfiddle.net/NZ2FJ/
As you can see in the example above, data-placeholder="true" is not working.
Can anyone suggest workaround please?
Also the official document does not show the placeholder.
Thanks in advance.
<div data-role="fieldcontain">
<label for="subject"><em>* </em> Subject: </label>
<select name="subject" id="subject" class="required" data-placeholder="true" data-native-menu="false">
<option value="" >Select subject</option>
<option value="Art">Art</option>
<option value="Band">Band</option>
<option value="Choir">Choir</option>
<option value="Design">Design</option>
<option value="Drama">Drama</option>
...
...
</select><br />
</div>
You have added the attribute data-native-menu="false" which is causing jQM to behave this way
You Example:
http://jsfiddle.net/NZ2FJ/1/
Without the attribute:
http://jsfiddle.net/NZ2FJ/3/
if you want to keep the data-native-menu="false" attribute so you get a pop-up selection box, simply make the first option selected from you js on pageload:
$(document).ready(function () {
$("#subject option:first").attr('selected', 'selected');
});
I updated jquery Mobile to 1.2.0 and it works fine now.

How to validate radio buttons, selects, and checkboxes on iPad

JSFiddle demonstrating the problem... http://jsfiddle.net/9Lzj6/2/
I am using the jQuery Validation Plugin http://docs.jquery.com/Plugins/Validation && https://github.com/jzaefferer/jquery-validation to validate a form.
JS
<script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>
<script type="text/javascript">
$("#patient_info_form").validate({
rules: {
"data[gender]": {required :true},
"data[dob_month]": "required",
"data[dob_day]": "required",
"data[dob_year]": "required"
}
});
</script>
HTML
<form id="patient_info_form" name="patient_info_form" action="..." method="post">
<select name="data[dob_month]" id="data[dob_month]" required="required">
<option value="" selected="selected"></option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
</select>
<select name="data[dob_day]" id="data[dob_day]" required="required">
<option value="" selected="selected"></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select name="data[dob_year]" id="data[dob_year]" required="required">
<option value="" selected="selected"></option>
<option value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
</select>
<label for="gender_male" class="button_gender male">
<input type="radio" name="data[gender]" value="male" id="gender_male" required="required">
</label>
<label for="gender_female" class="button_gender female">
<input type="radio" name="data[gender]" value="female" id="gender_female" required="required">
</label>
</form>
iPad PROBLEM
It works perfectly in a standard browser (tested in Chrome), but it doesn't work at all on an iPad. I am 100% new to programming for an iPad and (unfortunately for me) this site will only be accessed via iPad.
Is there something more I need to do with the jQuery Validation Plugin to get it to work on an iPad? I also tried jQuery Mobile without luck, but I'm willing to give it (or anything else) another shot with guidance.
Can someone please provide links to a tutorial, plugin, or example code that will show me how to validate selects, radio groups (no default, but one selection required), and checkboxes (no default, but one selection from a list required - not shown in the example code above but I will need that too)?
P.S. I don't need a popup or error message. I simply need to stop the form submission if all the requirements are not met.
Thanks in advance for the help.

DropDownList automatically closes in Firefox

I have several forms in ASP.Net MVC.
I noticed that some of the dropdowns close automatically in FireFox, but not in IE.
I don't have any Javascript or JQuery with triggered actions on any of these dropdowns.
Any ideas on why this is happening?
<form action="Index" id="MyID" method="get"><label>
Search <input id="searchWord" name="searchWord" type="text" value="" />
Category <select id="CategoryID" name="CategoryID"><option value="">-- Select All --</option>
<option value="1">Item A</option>
<option value="2">Item B</option>
<option value="3">Item C</option>
<option value="4">Item D</option>
<option value="5">Item E</option>
</select>
</label>
<label>
<input class="button" value="Search" type="submit" />
</label>
</form>
The dropdown list is coded using Razor as:
#Html.DropDownList("CategoryID", "-- Select All --")
The <label> tag defines a label. You have wrong close tag for <label>.

Resources