How to show th:value in Thymeleaf date format? - html

I have a problem with Thymeleaf date format when I send a date. The HTML shows the date correctly within a h3 tag but not inside the code of the datepicker and I can not understand why....
<div>
<label for="birthdate" th:text="#{editprofile.about4.birthdate}">Birth date</label>
<label class="input">
<i class="icon-append fa fa-calendar"></i>
<input type="date" name="date" id="birthdate" class="form-control margin-bottom-20" th:value="${#dates.format(profile2about2th.birthdate,'yyyy/MM/dd')}" th:field="*{birthdate}">
</input>
</label>
<h3 th:text="${#dates.format(profile2about2th.birthdate,'yyyy/MM/dd')}"></h3>
</div>
why it shows the date with hours in one place and correctly in the other...... input type="date" name="birthdate" id="birthdate" class="form-control margin-bottom-20" value="1932-10-10 00:00:00.0"
Thanks

th:field and th:value shouldn't be used on the same tag. (th:field sets the name, id and value attributes of the tag it is on.) You'll see that you would get the correct formatting if you left off th:field, but then the form wouldn't submit correctly. In my opinion, the way to fix this is to:
Add an InitBinder method to your controller, like this:
#Controller
public class WhateverController {
.
.
.
#InitBinder
public void initBinder (WebDataBinder binder) {
binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy/MM/dd"), true));
}
.
.
.
}
Remove the th:value. Your HTML should look like this:
<div>
<label for="birthdate" th:text="#{editprofile.about4.birthdate}">Birth date</label>
<label class="input">
<i class="icon-append fa fa-calendar"></i>
<input type="date" name="date" id="birthdate" class="form-control margin-bottom-20" th:field="*{birthdate}" />
</label>
<h3 th:text="${#dates.format(profile2about2th.birthdate,'yyyy/MM/dd')}"></h3>
</div>
There are ways to add global binders as well, if you want this to work for your entire application and not just that one controller.

Ensure that the date passed in as value (in this case birthdate) is of this format:
yyyy-mm-dd
and NOT in the date picker's format mm/dd/yyyy
Read more here.

Related

how to display date in HTML Date control using angular 13

While performing the edit operation using angular 13, I'm using HTML input type date. When fetching a date from the database, it is not showing the date in the textbox. Kindly help me.
update-movie.component.html
<div class="mb-2">
<label>Release Date</label>
<input type="date" name="releaseDate" class="form-control" [(ngModel)]="movieService.movieData.releaseDate"
#releaseDate="ngModel" [value]=movieService.movieData.releaseDate required
[class.is-invalid]="releaseDate.invalid && releaseDate.touched">
</div>```
I found the answer, instead of [value] I used [ngModel] and applied date pipe.
<label>Release Date</label>
<input type="date" name="releaseDate" class="form-control" [(ngModel)]="movieService.movieData.releaseDate"
#releaseDate="ngModel" [ngModel]="movieService.movieData.releaseDate | date : 'yyyy-MM-dd'" required
[class.is-invalid]="releaseDate.invalid && releaseDate.touched">
</div>

How to change date input type to DD/MM/YYYY in Angular?

I am using property as input type ="datetime". But this property view the output MM/DD/YYYY. so how do I change the output format of the Date to DD/MM/YYYY?
pick the date format mm/dd/yyyy
<div class="form-group">
<label>{{"StartDate" | localize}}*</label>
<input required class="form-control m-input" type="datetime" bsDatepicker
datePickerMomentModifier [(date)]="ticketWorkDetail.workDetailStartDate"
id="TicketWorkDetail_WorkDetailStartDate"
name="TicketWorkDetail_WorkDetailStartDate">
</div>
If you are using ngx-bootstrap... I think you are from the bsDatepicker directive on your input. You can use the bsConfig directive to format the date input. https://valor-software.com/ngx-bootstrap/#/datepicker#format
<div class="form-group">
<label>{{"StartDate" | localize}}*</label>
<input required class="form-control m-input" type="text" bsDatepicker
datePickerMomentModifier [(date)]="ticketWorkDetail.workDetailStartDate"
[bsConfig]="{ dateInputFormat: 'DD/MM/YYYY' }"
id="TicketWorkDetail_WorkDetailStartDate"
name="TicketWorkDetail_WorkDetailStartDate">
</div>
You can set the input type attribute to text and the bsDatepicker directive will do it's work.

Linking custom HTML Form to Google Form (How to handle Date input?)

I am trying to link a custom HTMl form to an existing Google Form. I have matched the action and name attributes to the form (placeholders in html snippet below for privacy).
My custom Form
<form action="https://docs.google.com/forms/PLACEHOLDERurl" method="post">
<div class="form-group">
<label class="mb-0" for="name">First & Last Name</label>
<input class="form-control" name="entry.PLACEHOLDER" type="text" id="name" placeholder="Enter name" required>
</div>
<div class="form-group">
<label for="date" class="mb-0">Pick Up Date</label>
<input id="pick-up-date" type="date" class="form-control">
</div>
<button id="testFormSubmit" type="submit" value="submit" class="btn btn-main-color">Submit</button>
</form>
However, there are 3 "name" attributes for the date input on the google form.
Main date input from Google Form
<input type="date" class="quantumWizTextinputPaperinputInput exportInput" jsname="YPqjbf" autocomplete="off" tabindex="0" value="" data-initial-value="2020-04-14" badinput="false" dir="ltr">
3 hidden inputs for each name value (year, day, month) from Google Form
<input type="hidden" name="entry.2099319546_year" jsname="L9xHkb_year" value="2020">
<input type="hidden" name="entry.2099319546_month" jsname="L9xHkb_month" value="4">
<input type="hidden" name="entry.2099319546_day" jsname="L9xHkb_day" value="14">
Can someone please let me know how I can alter my custom date form input to match this format?
I was dealing with same problem but turns out the solution is pretty easy.
You just need to delete the underscore value ('_year') and use only the entry id.
entry.2099319546
Doesn't matter that they have three different inputs and you only have one, Google will recognize it no matter way.
Check this tutorial from Codepen

How to open owl ng datepicker via icon trigger

Right now I am using owl ng datepicker - as shown in the image(https://daniel-projects.firebaseapp.com/owlng/date-time-picker). But it is opening on input field click. I want it to be opened on datepicker icon click in my input box.
here is the html code for the same.
<input id="fromDate"
name="fromDate"
type="text"
placeholder="From Date"
class="form-control"
tooltip="From Date"
delay="500"
triggers=""
#fromDateToolTip="bs-tooltip"
(mouseenter)="fromDateToolTip.show()"
(mouseleave)="fromDateToolTip.hide()"
[(ngModel)]="fromDatePicker"
[owlDateTime]="dt1"
[owlDateTimeTrigger]="dt1"
readonly="readonly"
(ngModelChange)="dateFilter()"
(keydown.backspace)="clear()">
<owl-date-time
[pickerType]="'calendar'"
[startAt]="startAtFromDate"
[showSecondsTimer]="true"
(afterPickerClosed)="setFromDateSelected($event,dt1)"
(afterPickerOpen)="fromDatePickerOpen()"
#dt1>
</owl-date-time>
remove [owlDateTimeTrigger]="dt2" from input field and place it some where in icon field.
<div class="example-wrapper">
<h2>Trigger Picker by a Icon</h2>
<label class="example-input-wrapper">
Date Time
<input placeholder="Date Time:" [(ngModel)]="dateTime" [owlDateTime]="dt2">
<span class="example-trigger" [owlDateTimeTrigger]="dt2">
<i class="fas fa-calendar-alt"></i>
</span>
<owl-date-time #dt2></owl-date-time>
</label>
<h4>Value From Picker: {{dateTime}}</h4>
</div>
You can use the owlDateTimeTrigger property.
The date time picker that this trigger is associated with.
Try with this:
<input id="fromDate" placeholder="From Date" ... [owlDateTime]="dt1 [owlDateTimeTrigger]="dt1">
<span [owlDateTimeTrigger]="dt1"><i class="fa fa-calendar"></i></span>
<owl-date-time [pickerType]="'calendar'" [startAt]="startAtFromDate [showSecondsTimer]="true" (afterPickerClosed)="setFromDateSelected($event,dt1)" (afterPickerOpen)="fromDatePickerOpen()" #dt1></owl-date-time>

HTML Text label misplaced when in line validation appears

I have a simple form with a date validation which works fine:
The problem is that when the validation kicks in, the "End Date" label gets misplaced as you can see (is above the date field box/calendar):
The code related is the following (it's just a form):
<form name="senstageaddform">
<div class="form-element">
<label for="ed_senStartDate" class="text-label">
{{i18n "EDUCATION_SEN_START_DATE"}} <span class="required">*</span>
</label>
<input type="text" class="date standard-text-field" maxlength="16" id="ed_senStartDate" name="startDate"/>
</div>
<div class="form-element">
<label for="ed_senEndDate" class="text-label">{{i18n "EDUCATION_SEN_END_DATE"}}</label>
<input type="text" class="date standard-text-field" maxlength="16" id="ed_senEndDate" name="endDate"/>
</div>
</form>
Is there any way to "pack" the form or any way to stop this happening?
Any hint please?
Thanks everyone