Field not displayed with condition - thymeleaf

I use thymeleaf 3
I try to use a condition with th:attr with some value
<input type="text" class="form-control" th:id="'genericForm'+${genericField.field}" th:attr="${genericField.mandatory} ? data-msg=#{mandatory.field}, name=${genericField.field} : name=${genericField.field}"/>
Actually, this input is not displayed
error is:
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as assignation sequence:
Any idea?

Like this is how I would do it:
<input type="text" class="form-control" th:id="'genericForm'+${genericField.field}" th:name="${genericField.field}" th:attr="${genericField.mandatory} ? data-msg=#{mandatory.field}"/>
You can move name out to th:name since it's in both.

Related

ngModel is not working with value attribute in ngx-material-timepicker with input in Angular7?

I have used ngx-material-timepicker for implementing the time filter.in our case time picker is open properly but its not working in the following scenarios:
Case 1 :
1.initially i have set selected time in the input and it working properly now this time i am not using with [(ngModel)]
<input [ngxTimepicker]="defaultValue" [value]="'05:11 pm'" (change)="selectChanged($event)">
<ngx-material-timepicker #defaultValue></ngx-material-timepicker><br>
Case 2 :
2.Now we have add [(ngModel)] for get the selected value that is selected fro the picker but now this time out initially set value is not showing in the input but if i remove the [(ngModel)] its working:
<input [ngxTimepicker]="defaultValue" [(ngModel)]="date1" [value]="'05:11 pm'" (ngModelChange)="selectChanged($event)" >
<ngx-material-timepicker #defaultValue></ngx-material-timepicker><br>
I have also post above issue in the github but get any response,please tell me anyone how to fix above issue.
I've got the same problem but in my case my inputs are into form and i forget about the name propriety.
i just added the name="date" in the input tag
<mat-form-field class="toggle-example" style="width: 100%">
<input matInput [(ngModel)]="time" [ngxTimepicker]="toggleTimepicker" name="time" [format]="24" [disableClick]="true" readonly>
<ngx-material-timepicker-toggle matSuffix [for]="toggleTimepicker"></ngx-material-timepicker-toggle>
<ngx-material-timepicker #toggleTimepicker></ngx-material-timepicker>
</mat-form-field>
I have fixed issue via below code:
<input [ngxTimepicker]="defaultValue" [(ngModel)]="date1 == undefined ? defaultValue : date1" [value]="'05:11 pm'" (ngModelChange)="selectChanged($event)" >
I think the onchange that you were asking is to set the time
You can use [timeset]="(setTime())" inside your ngx-time-picker tag
And in your ts file write the set time method.
I used this step and succeeded
<mat-form-field>
<input aria-label="default time" matInput [ngxTimepicker]="defaultValue" [value]="'9:00 am'" readonly>
<ngx-material-timepicker (timeSet)="setTime($event)" #defaultValue>
</ngx-material-timepicker>

Razor broken when a space between HTML’s attribute and its value

I have a ViewBag like this
ViewBag.ApplyDiscount = false;
ViewBag.ExpressShip = true;
ViewBag.Supplier = null;
and some cshtml snippets like this
Discount:<input type="checkbox" checked="#ViewBag.ApplyDiscount"/>
Express:<input type="checkbox" checked="#ViewBag.ExpressShip"/>
Supplier:<input type="checkbox" checked="#ViewBag.Supplier"/>
after razor rendered the cshtml snippets,the real html will be
Discount:<input type="checkbox"/>
Express:<input type="checkbox" checked="checked"/>
Supplier:<input type="checkbox"/>
but if I add a space between the checked attribute and =like
Discount:<input type="checkbox" checked ="#ViewBag.ApplyDiscount"/>
Express:<input type="checkbox" checked ="#ViewBag.ExpressShip"/>
Supplier:<input type="checkbox" checked ="#ViewBag.Supplier"/>
razor will render the cshtml snippet in a wrong way. The html will be like this:
Discount:<input type="checkbox" checked ="False"/>
Express:<input type="checkbox" checked ="True"/>
Supplier:<input type="checkbox" checked =""/>
This will happen no matter MVC4(VS2012) or MVC5(VS2015).
So, can anyone tell me why a space will cause this thing to happen?
Because checked itself is a special stand-alone boolean attribute from legacy HTML and can be valid syntax without an attribute value.
It's presence alone indicates that the box is checked.
e.g.
<input type="checkbox" checked />
and
<input type="checkbox" checked="true" />
Perform the same way. It's why in jquery we always use the :checked selector. It obfuscates the need to check the variation.

grails: select like numeric up down

I've searched around the net but I have not found a solution.
Is there something like numeric up down, for numeric selection in Grails?
How can I create it?
You can achieve your requirement via simple html as:
<input type="number" name="quantity">
you can set range also as:
<input type="number" name="quantity" min="1" max="5">
and If you want you can add value attribute to be shown as:
<input type="number" name="quantity" min="1" max="5" value="${domainInstace.attribute}">
and Enjoy.......
Within a gsp ?
<g:select id="orderby" name="orderby" from="${1..10}" noSelection="['':'-Define Display Order 1 top 10 bottom-']" required="" value="${youdomainClassInstance?.orderby}" class="many-to-one"/>

All radioButtons are false at the view

#Html.RadioButton("smth",true)
This row at the page looks like UNCHECKED radioButton. Why?
You should use
HtmlHelper.RadioButton(string name, object value, bool isChecked)
extension method.
First argument is the name of the form field which is input field generated by html helper.
Second argument is the value of input element. If this radio is selected when the postback to server happens, this value is used.
Third argument is what you are looking for. If it is true it makes radio button selected.
For instance,
#Html.RadioButton("Name", "Value" ,true)
would generate an input element which looks like following,
<input checked="checked" id="Name" name="Name" type="radio" value="Value" />
You need to use something of the form
#Html.RadioButton(id,value,checked (bool true/false))
So
#Html.RadioButton("A","B",true)
For example would produce:
<input checked="checked" id="A" name="A" type="radio" value="B" />
The documentation for this is here
In your previous query, you got this answer.
You asked the same query in it's comment section. The problem was that the second line of code was missing one parameter.
Please check below details....
Parameter Details
Razor Syntax
#Html.RadioButton("smth", "smth", true)
#Html.RadioButtonFor( m => m.Prop, true, new { id = "rdBtn" } )

Grails check checkbox with value same as variable

Hi I have this value that I passed to the gsp
${d.causalOrganism}
I have this three checkboxes and I want one of them to be checked based on the above value. How can I do so? I tried but doesn't work.
<label for="causalOrganism">Causal Organism:</label>
Fungi<input type="checkbox" value="Fungi" name="causalOrganism" id="causalOrganism1" onclick="checkOrganism(this.id)"/>
Bacteria<input type="checkbox" value="Bacteria" name="causalOrganism" id="causalOrganism2" onclick="checkOrganism(this.id)"/>
Virus<input type="checkbox" value="Virus" name="causalOrganism" id="causalOrganism3" onclick="checkOrganism(this.id)" />
Add the checked attribute to your checkbox based on your desired condition:
...
Fungi<input type="checkbox" value="Fungi" name="causalOrganism" id="causalOrganism1" onclick="checkOrganism(this.id)" ${(d.causalOrganism == 'causalOrganism1') ? "checked='checked'" : ''}/>
...
You should think about using the grails checkBox. With this you could use the checked attribute directly.

Resources