Set default value of dropdown through grails paramater - grails

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>

Related

how to thymeleaf select row value parameter jquery function?

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>

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>

How to make a select box with constant list items with g:select

I would like to make a select box using <g:select/> that translates to this html:
<select id="myselect" name="myselect">
<option value="r">RED</option>
<option value="g">GREEN</option>
<option value="b">BLUE</option>
</select>
I would also like the value to be preselected from a bean when the page reloads.
I'm doing this inside a so I have a table with each row having a separate option box.
I'm currently accomplishing this in the below html:
<g:each in=${mylist} status="i" var="myInst">
<select id="status${myInst}" name="status${myInst}" data-id="${myInst.id}">
<option value="r" <g:if test="${myInst.color == "r"}">selected</g:if>>RED</option>
<option value="g" <g:if test="${myInst.color == "g"}">selected</g:if>>Green</option>
<option value="b" <g:if test="${myInst.color == "b"}">selected</g:if>>BLUE</option>
</select>
</g:each>
This all works fine but I'd like to change that ugly <select> into <g:select>
<g:select id="myselect" name="myselect" value="${myInst.color}"
from="${['r': 'RED', 'g': 'GREEN', 'b': 'BLUE']}"
optionKey="key" optionValue="value" />
you have to declare the "myselect" inside your domain class. I have been having trouble with this too, but I'm about 2 weeks ahead of you. see how do I write a set for g:select tag

Resources