how to thymeleaf select row value parameter jquery function? - thymeleaf

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>

Related

how to set selected value in drop down menu depending on conditions

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 –

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

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

How to select option in HTML select using TAL in ZPT?

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>

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