I'm trying to generate a select drop down with an option preselected (based on params) using the fields plugin. The code below generates a select box with the proper elements and everything works except it doesn't add "selected" to the option tag. It seems to be ignoring my widget- attributes.
From what I understand the fields plugin will pick g:select in this case by default if not overridden, and you can use widget- to pass arguments to it.
What am I doing wrong?
<f:field bean="specialUser" property="user" label="user.label" widget-optionKey="id" widget-value="${params.user?.id?:value?.id}"/>
Link to the fields documentation:http://grails3-plugins.github.io/fields/snapshot/guide/single.html#
This seems to have done what I wanted, computed specialUserList from the controller. Though it would've been nice to utilize the "widget-" to do this form me.
<f:field bean="specialUser" property="user" label="user.label">
<g:select id="user" name="user.id" optionKey="id" class="span-8 margin-bottom-none" from="${specialUserList}" noSelection="${['null': message(code: 'common.list.select')]}" value="${params.user?.id}"/>
</f:field>
Related
Say I have the following q-input:
<q-input
v-model="form.email"
inverted-light
color="white"
stack-label="Email:"
type="email"
#blur="$v.form.email.$touch"
:error="$v.form.email.$error"/>
I'd like to be able to make it so that if the domain of the email is mydomain.com that the form action will change to another website (without csrf protection) and the POST will be made to that website instead of the main one.
To do this I was thinking I could use jQuery. eg. $('#email').val().replace(/^.+#/, '') == 'mydomain.com' then change the form action and submit.
The only problem is: I don't know how to set an id attribute on q-input.
Any ideas?
As of early Quasar 1.4.2 (November of this year) you can specify the id value on the resulting html generated by q-input by using the "for" property (see the end of the behavior properties: https://quasar.dev/vue-components/input#QInput-API).
So, for example, you could add for="myInputId":
<q-input
v-model="form.email"
inverted-light
color="white"
stack-label="Email:"
type="email"
#blur="$v.form.email.$touch"
:error="$v.form.email.$error"
for="myInputId"
/>
The id attribute with value "myInputField" will end up on the resulting <input> element in your HTML.
Not using the "for" in the elements gave me a lot of headaches because the Jest snapshot generated random IDs
I have the following codeline in my grails view
<g:select id="partner" name="partner.id" from="${org.strotmann.partner.Partner.partners}" optionKey="id" value="${auftragInstance?.kundenNr}" class="many-to-one" noSelection="['null': '']"/>
I expect it to show me the list specified in the from clause as a select box (that works fine)
After selecting an Item from the box I expect that it stores the id of that Item in the field specified in the value clause ( that does not work, always null)
I'm somewhat confused, because the followin codeLine does exactly what I expect:
<g:select id="partner" name="partner.id" from="${org.strotmann.partner.Partner.partners}" optionKey="id" value="${arbeitsgangInstance?.kundenNr}" class="many-to-one" noSelection="['null': '']"/>
Can anybody tell me where I can find a difference or how to recode my ?
peter
let me reformulate my question:
I have a list
org.strotmann.partner.Partner.partners
It contains partners with just the attribute name and of course the id.
I want the names in a selectList and want the id of a partner stored in
auftragInstance.kundenNr
feel free to code a working g:select
peter
The value attribute is used to provide the initial selection. The name attribute will contain the selected value when the form is submitted. In a controller you can get it like this:
def partner = params.partner
See:
select tag in grails documentation
thanks to comment from masc I found that there was just missing the following code snippet in save and update method of AuftragController:
if (params.partner.id == 'null')
salesOrderInstance.kundenNr = 0
else
salesOrderInstance.kundenNr = params.partner.id.toLong()
That code block was allready contained in ArbeitsgangController, and therefore the second html-line in my question was working fine.
the following select (with id and value clauses omitted) will also do:
<g:select name="partner.id" from="${org.strotmann.partner.Partner.partners}" optionKey="id" class="many-to-one" noSelection="['null': '']"/>
sorry the value entry
value="${auftragInstance?.kundenNr}"
must not be removed, it is important for update.
I have a select box of TYPES that each type has their own PARAMETERS. The TYPES select box will fire off some AJAX that calls a template and renders PARAMETER select boxes on my view. The Parameters are made up of name:value pairs, thus every name can have many values.
Some parameters need multiple='true' for the user to select multiple values for each name, while other parameters need to be restricted to only one choice.
In my gsp page I have a bunch of these:
<g:if test="${it?.getKey().toString().equals('PARAMETER_A')}">
<td><g:select multiple="true" optionKey="id" optionValue="value" name="sampleParameters" id="parameter" value="${params?.sampleParameters}" from='${it?.getValue().sort()}'></g:select></td>
</g:if>
<g:if test="${it?.getKey().toString().equals('PARAMETER_B')}">
<td><g:select multiple="true" optionKey="id" optionValue="value" name="sampleParameters" id="parameter" value="${params?.sampleParameters}" from='${it?.getValue().sort()}'></g:select></td>
</g:if>
My issue is that I have 6 parameters for one particular TYPE that need to select multiple values, the rest do not. Rather than explicitly type out as above, is there a way that I can test for more than one thing in a g:if statement like you can in java? such as:
if(something.equals(PARAMETER_A) || something.equals(PARAMETER_B))
etc.
Is there a way to do something similar to java's approach in groovy?
Grails g:if just uses groovy in its test attribute. So to answer your question, yes:
<g:if test="${something.equals(PARAMETER_A) || something.equals(PARAMETER_B)}">
</g:if>
I have Three checkbox
<g:checkBox name="startAccountingStatus" value="Yes" />
<g:checkBox name="startAccountingStatus" value="No" />
<g:checkBox name="startAccountingStatus" value="NA" />
i want something like RadioGroup. Here now i can select all the checkBoxes. i dont want that..
I can check only one checkBox.
I can do it in jQuery which i dont want to ..
Is there any way of achieving it in Grails Gsp.
Why don't you go with HTML radio group, also present in Grails?
You can make radio items look like checkbxes.
If you want the check be made on the client browser and not checked at server side after submission the only way is via javascript (jquery, prototype or simple javascript it's little important)
With the <g:select> tag... sometimes it displays normally like a selection drop down box, while sometimes it displays with multiple rows, this is very annoying.... Even I put the size="1" into the <g:select>, it still displays multiple rows... is there anyone knows how to make <g:select> display correctly? with only one item visible, like a dropdown box. Thanks!!
<g:select size="1" id="s_caseID" name="s_caseID" value="${t1T2InstanceListTotal?.Accession_No}"
noSelection="${['null':'Select One...']}"
from='${t1T2InstanceListTotal}'
optionKey="Accession_No" optionValue="Accession_No" onclick="this.form.submit();" >
</g:select>
Here's the taglib code that cause the multiple="multiple" attribute to be rendered (if not explicitly declared on the tag):
def value = attrs.remove('value')
if (value instanceof Collection && attrs.multiple == null) {
attrs.multiple = 'multiple'
}
Therefore, it looks like you're passing a Collection as the <g:select>'s value attribute instead of a single value. Is that what you're intending to do?
Set the multiple attribute to false
<g:select name="cars"
from="${Car.list()}"
value="${person?.cars*.id}"
optionKey="id"
multiple="false" />
If the "value" is a list, g:select always considers it as a multiple select. To avoid this and have a single select drop-down just ignore the value attribute and use keys option instead!
This works fine for me!
`<g:select id="s_caseID" name="s_caseID" from='${t1T2InstanceListTotal}'
noSelection="${['null':'Select One...']}"
keys="${t1T2InstanceListTotal?.Accession_No}" onclick="this.form.submit();">
</g:select>`