On my gsp-page I've dropdown list. The code below:
<g:select name="tablePlacesAvailable" from="${tableInfo}"
optionValue="${{it.placesInTableAmount}}"
optionKey="placesInTableAmount" value=""/>
It shows non-unique results. How to fix it?
You can modify your code as per following .
<g:select name="tablePlacesAvailable" from="${tableInfo.unique()}" optionValue="${{it.placesInTableAmount}}" optionKey="placesInTableAmount" value=""/>
Related
Data is not retrieving by g:select in Grails 3.
My code is like below-
<g:select from="${Machine_summaryList}" name="brand" />
Here "Machine_summaryList" is List of "Machine_summary" class and "brand" is the column which data I need to retrieve.
You need to use optionValue="brand" in this case.
Your g:select must be like:
<g:select from="${Machine_summaryList}" name="brand" optionKey="id" optionValue="brand"/>
When the form will submit, you will receive the selected Machine in params.brand.
Just this procedure works for me
<g:select from="${project.Machine_summary.executeQuery("select distinct c.brand from Machine_summary c")}" name="brand" />
how to put values in select tag in grails.
<g:select name="country_name" > </g:select>
like all country name USA,UK,AUS,SA,CAN,INDIA
<g:select name="country_name" from="${['USA','UK','INDIA']}"> </g:select>
through this you can put values manually
from="${['USA','UK','INDIA']}
I'm performing inline validation on fields as the user tabs between them.
A problem occurs when there is more than one error against a field i.e both errors are shown.
I only want to show one error (The first one for arguments sake).
Is there are different tag to deal with this?
<jqvalui:renderError for="title">
<g:eachError bean="${objInstance}" field="title"><g:message error="${it}" /></g:eachError>
</jqvalui:renderError>
Thanks
So essentially you just have to use the errors themselves instead of using the tags provided for you.
<g:hasErrors bean="${objInstance}" field="title">
<g:message error="${objInstance.errors.getFieldErrors("title")[0]}" />
</g:hasErrors>
I know it's like a hack but if no exact solutions...
Consider adding a flag or a counter and set/test it inside the loop:
<g:set var="isErrorShown" value=""/>
<g:eachError bean="${objInstance}" field="title">
<g:if test="${!isErrorShown}">
<g:message error="${it}"/>
<g:set var="isErrorShown" value="TRUE"/>
</g:if>
</g:eachError>
I have this snippet of code below. I want to pass the value of the select availabilityChoice as a second parameter to my updateAvailability javascript method.
I've tried everything (including an optionKey). How do you do this?
<label>Select Contact Availability:</label><g:select name="availabilityChoice" from="${['Inactive', 'Active']}" value=""/>
<g:actionSubmit type="button" value="Update Availability" onclick="updateAvailability('contactList', availabilityKey.value);"/>
I should add that contactList is a list of check boxes that were selected. So I need to pass that list of selected checkboxes, the value of the select box, and update those selections with the value in the select box.
Set an ID for <select> by using id attribute, and then you can refer to that element in javascript.
<label>Select Contact Availability:</label>
<g:select id="mySelect" name="availabilityChoice" from="${['Inactive', 'Active']}" value=""/>
<g:actionSubmit type="button" value="Update Availability" onclick="updateAvailability('contactList', document.getElementById('mySelect').value);"/>
I am running into an issue where by I want to pass form elemets that gets generated dynamically as such id's of those elements are dynamic as well.
Here is the code snippet I am running
<g:each in="${selectedList}" status="i" var="menuForCity">
<td><input type="checkbox" id="${100+i}" name="check_list" value="${city.id}" checked="checked" /></td>
<g:select name="myClass.id"
from="${instances}"
onchange="${remoteFunction(
controller:'cityPlan',
action:'test',
params:'\'id=\'+this.value+\'\'&cityid=\'+document.getElementById(100+i).value',
update:(i+1))}"
optionKey="id" />
...
Problem I am running into is how to get id of dynamic checkbox thats created in the form ?
Is there any way I can write/evaluate gstring ?
...
params:'\'id=\'+this.value+\'\'&cityid=\''+city.id,
update:(i+1))}"
optionKey="id" />
...
I'm not answering your question but there's an extra single quote in your code that shouldn't be there in the first place, that might solve your problem.
params:'\'id=\'+this.value+\'\'&cityid=\'+document.getElementById(100+i).value',
should be:
params:'\'id=\'+this.value+\'&cityid=\'+document.getElementById(100+i).value',