<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
Related
I have code with drop down menu. The object for this menu has few fields. Two of them are playerPosition and isFirstSquadPlayer.
If isFirstSquadPlayer is TRUE I need to display in menu player.playerPosition.
Trying on few ways but failed.
My controller:
public String players(#PathVariable long clubId, Model model) {
Club club = this.clubRepository.findByClubId(clubId);
model.addAttribute("players", this.playerRepository.findAllByPlayerClub(club));
return "players";
}
My HTML:
<select name="playerposition"
id="createnewplayerposition" th:value="${player.playerPosition}" required>
<option value="0">Select position for player</option>
<!--HERE NEED PROPER REQUEST -->
<option th:selected="${player.playerPosition}" th:text="${player.playerPosition}"></option>
<option value="GK">Goalkeeper</option>
<option value="RWB">Right Wingback</option>
<option value="RCB">Right Centreback</option>
(...)
</select>
as per kindly advice:
ok, tried and found such request with thymeleaf conditional:
<option th:if="${player.playerPosition!=null}" th:selected="${player.playerPosition}" th:text="${player.playerPosition}"></option>
it's not excactly how I expected but gives some solution –
How can I send the selected line value?
<select th:onchange="changes(this.getAttribute('data-test'))">
<option th:each="list : ${allList}"
th:value="${list?.number}"
th:text="${list?.name}"
th:data-test="${list?.test}">
</option>
</select>
onchange(list.test) value parameter ....
This should work (in your case, this refers to the select object, and not an option).
<select th:onchange="changes(this.options[this.selectedIndex].dataset.test)">
<option th:each="list : ${allList}"
th:value="${list?.number}"
th:text="${list?.name}"
th:data-test="${list?.test}">
</option>
</select>
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[]
I got the following drop-down list - SELECT element - construction in my ZPT template:
<select id="record_selector">
<option tal:repeat="record view/records" tal:attributes="value record/id">
<span tal:replace="record/name"></span>
</option>
</select>
How make it possible to have selected OPTION which value is equal to one from the corresponding view property (i.e. for example, OPTION tag value == view/currentRecordId then make it selected).
Using the sdupton's clue, I got the following solution:
<select id="record_selector">
<tal:block tal:repeat="record view/records">
<option tal:condition="python: record['id'] != view.recordId"
tal:attributes="value record/id"
tal:content="record/name">
</option>
<option tal:condition="python: record['id'] == view.recordId"
tal:attributes="value record/id"
tal:content="record/name"
selected>
</option>
</tal:block>
</select>
TAL conditionals are awesome :)
I found another solution here: https://old.zope.org/Members/peterbe/DTML2ZPT/index.html#example14
This still works with Zope 5.3 on Python 3.
<select id="record_selector">
<option
tal:repeat="record view/records"
tal:attributes="
value record/id;
selected python: record['id'] == view.currentRecordId">
<span tal:replace="record/name"></span>
</option>
</select>
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>