How to make group by DropDown list in MVC application? - asp.net-mvc

I have to Populate DropDown list of Country in MVC application. Where i have to make the Group as per the continent.. Any suggestion Help me alot Thanks

look how to do it in HTML
<select>
<optgroup label="G1">
<option value="c1">One</option>
</optgroup>
<optgroup label="G2">
<option value="s1">Two</option>
</optgroup>
</select>
u can implement by your own like here

Related

Get value from select tag on view send to controller in var ruby and rails

please can help me.
I am trying to get the values ​​of the "value" fields from my select_tag in rails and send it to the controller to use in variables to execute some commands, could help me follow my code.
This my view with 2 select_tags this is firsts select_tag one choice option and, go to second below
<select id="channel" name="channel"><option value="747">0800 0</option>
<option value="1750"> 0800 3</option>
<option value="1845"> 0800 1</option>
<option value="1839">0800 4</option>
<option value="1831">0800 5</option>
<option value="1326">08000 6</option>
<option value="1848">08000 7</option>
<option value="582">08000 8</option>
<option value="182">08000 9</option>
<option value="1838">0800 10</option></select>
This my view with the second select_tag choice one option with first select_tag.
<select id="opts" name="opts"><option value="578">opt 0</option>
<option value="470">opt 1</option>
<option value="577">opt 2</option>
<option value="600">opt 3</option>
<option value="539">opt 4</option></select>
i'm trying to get the values ​​of the two select_tags on my controller i'm studying rails and ruby ​​and i still couldn't do it could help me with my code
could show me how to receive these values ​​in the controller I'm looking for examples

Select2 getting multiple selections after form POST

I have this select2 multi-selection dropdown that works fine on the client side but only posts the last selection users make:
<select class="searchable-dropdown form-control form-control-md" name="payment_methods" id="payment-methods-send" multiple="multiple">
<%= options_for_select( (::Transaction::SEND_METHODS).collect{ |m| [t(m[:name]), m[:name].parameterize ]}, selected: params[:payment_method] ) %>
</select>
It generates the following markup:
<select class="searchable-dropdown form-control form-control-md" name="payment_methods" id="payment-methods-receive" multiple="multiple">
<option value="coupons">Coupons</option>
<option value="paypal">Paypal</option>
<option value="skrill">Skrill</option>
<option value="revolut">Revolut</option>
<option value="zelle">Zelle</option>
<option value="transferwise">Transferwise</option>
<option value="swift-bank-transfer">SWIFT bank transfer</option>
<option value="european-bank-transfer">European bank transfer</option>
<option value="us-bank-transfer">US bank transfer</option>
<option value="uk-bank-transfer">UK bank transfer</option>
<option value="check">Check</option>
</select>
I've used this to initialize the control:
$( ".searchable-dropdown" ).select2({ theme: "bootstrap" });
After making several selections and sending the form, I am getting this within params:
"payment_methods":"paypal"
Paypal was indeed selected (last) but so were a bunch of other selections.
Was it not supposed to send them comma-separated or something? Am I doing something wrong?
Nevermind, looks like I wasn't asking Google the right question...
Multiple select box is not working in rails
You need to make sure that you are sending an array of answers by
changing the name to payment_methods[]

How can I Use th:selected attribute in thymeleaf

<select name="fGroup-selector">
<option th:each="fGroup : ${fGroupsList}"
th:value="${fGroup.id}"
th:selected="${fGroup.is_default}"
th:text="${fGroup.name}">fGroup
</option>
</select>
It is not working....
This is thymeleaf dropdown list code in which th:selected attribute is not working Please any help me

Rails 3 two selects with the same options but keep values unique

I am trying to figure out how to deal with two select boxes with the same options (I am using formtastic gem) and force unique values. For example:
<select name="departure" size="1">
<option value="1">NY</option>
<option value="2">FL</option>
<option value="3">LA</option>
</select>
<select name="arrival" size="1">
<option value="1">NY</option>
<option value="2">FL</option>
<option value="3">LA</option>
</select>
The simplest way is to use jQuery, but I would like to know if there is any validation option in Rails 3 to handle such scenario. Thanks in advance!
You'll have to write your own I think.
validate :departure_cant_equal_arrival
def departure_cant_equal_arrival
if departure.present? and arrival.present? and (departure == arrival)
errors.add(:arrival, "can't be the same as departure")
end
end

Set default value of dropdown through grails paramater

I send a user to a page with setting the parameters using JS like this:
window.location='/myPgae/MyController?terminId='+terminId;
On the view page I want to set the dafult value of one drop-down menu from the parameter if it was sent.
Drop down:
<select name="terminId" dojoType="dijit.form.Select" style="width:180px;">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3 Tage</option>
</select>
If parameter was sent I want to set option3 as the selected value. I know there is an option selected="selected" but how can I do the check?
I've got it:
<g:if test="${params.terminId}">
<option value="option3" selected="option3">option3</option>
</g:if>
<g:else>
<option value="option3">option3</option>
</g:else>

Resources