I'd like to ask for help in Thymeleaf translation.
I can translate a static value if it is declared in my properties file with th:utext="#{message.key}", but I don't know how to translate an attribute's value on the page.
E.g. the status attribute of an account instance can be "Active" or "Blocked" and I'd like to translate these values.
I use th:utext="*{account.status}" to display the status value on the page.
Consider your message as below. See HTML portion for the EL
Message.properties
# Case 1 #
Active=User is active.
Blocked=User is blocked.
# Case 2 #
account_status_Active=User is active.
account_status_Blocked=User is blocked.
HTML
<!-- Case 1 -->
th:utext="#{${account.status}}"
<!-- Case 2 -->
th:utext="#{account_status_ + ${account.status}}"
Related
I have a Book domain with a Double variable Double commissionRate.
(e.g.) myBook.commissionRate = 0.0001
I am using the default Scaffolding. I didn't customize any of the views.
The show.gsp displays the Double as-is which is what I want.
(i.e.) 0.0001
However, the edit.gsp will show 1.0E-4 in the input box.
The code in the edit.gsp is just <f:all bean="book"/>
I look at the HTML split out from the view. The value in the HTML is also 1.0E-4. So, I think the Field plugin is converting 0.0001 to 1.0E-4.
Would you show me how to set up my book domain so the Field plugin (assuming the Field plugin is checking the data type and the constraint, and then make the conversion) will just show the value without the scientific notation in the edit.gsp please?
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 need to disable a select element in grails depending on its value. The problem is when I started to add the disable property something is quite wrong with the code.
An example is when the form is sent to the backend, its as if there is no value for that select element and the value sent is null. But, when I checked the DOM, there is a selected attribute in the element. I tried to remove that disabled property because I have a feeling that it has something to do with the bug that I'm encountering and I was right because after removing it, everything worked correctly again.
this is the select tag
<g:select name="detail-entryNameId"
value="${journalEntryName.savingId}"
from="${journalEntryNameInstanceList}"
optionKey="savingId"
optionValue="displayName"
readonly="${journalEntryInstance.paymentMade}"
/>
One more thing about this element is that it can occur as many as possible, which means I have a table and in every row, that element exist so I cannot simply manipulate it.
I've also read in this post how can i make a textfield read only in grails? that "If you use disabled="true" the value will not actually be submitted in the form, so the <g:field/> tag should be used." which proves that disable attribute affects the value of the element.
How can I disable the select element and at the same time, still get its value correctly?
The problem is that in HTML the mere existence of the disabled attribute disables the tag. The value of the attribute (true/false) is ignored.
In such cases the solution is to use an <g:if> to create the tag with or without the disabled attribute according to a condition.
In your case, since you want the value even when the tag is disabled you can add a <g:hiddenField> with the same name and value as the disabled select.
I am trying to validate the following:
<paper-input floatinglabel
id="ethinic-group"
label="Ethnic Group"
value='{{race.ethnicGroup}}'
validate="[A-Za-z'\s-]*"
error="Only letters, space and dash are allowed">
</paper-input>
If I put a number in the field, validation is not fired. Is there something else that I should add?
You can
- check the invalid attribute and for example change the appearance of the element depending on the attribute value
- listen on on-input-invalid='{{inputInvalidHandler}}' or `on-input-valid='{{inputValidHandler}}' and change the appearance by code
see http://www.polymer-project.org/docs/elements/core-elements.html#core-input for more details.
(As far as I know paper-input builds on top of core-input)
Update
Your regex is missing ^ and $
validate="^[A-Za-z'\s-]*$"
You had this already in HowTo add a required indicator to paper-input ;-)
See also Taking total control of PaperInput validation for an example about custom validation.
I have check boxes in a list
HTML Code
<g:checkBox id="isBookable_${index}" class=" isBookable" style = "width :auto" name='isBookable' value='${careProviderScheduleExceptionInstance?.isBookable}' />
Problem
When I get the list of this checkbox i.e isBookable in params, the values for only the checkboxes that are checked comes in the list and the value comes as on and not true.
I want the values should come as true or false based on if the checkbox is checked or not.
Thanks in advance.
Grails g:checkbox does some shenanigans for the binding magic to work correctly when you do something like:
def schedule = new Schedule(params)
So that schedule.bookable would get populated correctly. I've never been a big fan of how it works but it is what it is and at the end of the day, it does work for typical use cases.
You have to remember that per the HTML spec, you're not going to get unchecked checkboxes passed in on a form submit. So looking for false is a moot point. What you would have to do is take the ones that do get checked (and submitted) and compare that against a list of possible bookable 'schedules'.
A work around would be to use Javascript to submit your form and pass in all the checkbox's with whatever value you want mapped to the correct instance.