vaadin flow DateTimePicker returns null if only one field entered - datetimepicker

I'm using a DateTimePicker with vaadin flow 23.0.5.
The problem is that if a user only enters either the date or time (but not both), then when I save the field using a binder the result is a null LocalDateTime.
import com.vaadin.flow.component.datetimepicker.DateTimePicker;
private DateTimePicker noticeTwoDateTime;
noticeTwoDateTime = new DateTimePicker(label);
layout.add(field);
binder.forField(this.noticeTwoDateTime).bind(
NoticeTemplate::getNoticeDateTwo,
NoticeTemplate::setNoticeDateTwo);
Is there some way to warn the user that they must enter both?
I've explored using a validator but it only gets passed the LocalDateTime which of course is null.

First of all you can use a helper text as described here:
https://vaadin.com/docs/latest/ds/components/date-time-picker/#providing-input-guidance
And if that's not enough you can try to create your own validation routine and use it within the binder as e.g. here:
https://vaadin.com/docs/latest/flow/binding-data/components-binder-validation/#defining-validators
Could look similar to this then:
myDateTimeBinding = binder.forField(myDateTimePicker)
.withValidator(myDateTime -> Validation.validateDateTime(atdDateTimePicker.getValue()),
"Please pick Date and Time")
.bind(......
with Validation as your Validation Utils Class and validateDateTime as your method returning a boolean.

Workaround: If you mark the field as being required/mandatory then the DateTimePicker shows an error message, if one of both is missing.
Yeah sure, you don't want mark every date/time as required....
This problem seems to have existed already in Vaadin 14: Vaadin 14 DateTimePicker with optional time or warning for missing time

Related

How to sendkeys "time" in time type element?

I need to pass data in time format in "time" type element in "10:00 AM" format.
I am using following code:
public static void setShift()
{
txttime.sendkeys("1030AM");
}
this is not working. what is a correct way to enter such data?
Use Following Code :
It will work it for textbox/text area control
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm a");
Date date = new Date();
txttime.sendkeys(date);
For the HTML input type datetime-local handling it from selenium is not ideal. It is not the most used date time picker, and it is not supported in firefox or safari.
For chrome, the date time format shows the format set in the browser's machine.
If you haven't changed anything, I'm guessing you are getting the format shown in the guru99 tutorial.
If that is the case, then you have missed that they also have provided the solution there.
After entering the date part you need to press tab to input the time part. Which is missing from your given code.
Try this:
First, input the date
WebElement dateBox = driver.findElement(By.xpath("//form//input[#name='bdaytime']"));
dateBox.sendKeys("09252013");
Second, press tab
dateBox.sendKeys(Keys.TAB);
Last, input the time
dateBox.sendKeys("0245PM");
Note:
If your machine has different DateTime formatting then this might not work. You have to check which part of the date time senKeys can actually input then split up that part and use Keys.TAB to press tab. Then input the next part until completion.

Protractor sendKeys issue with scripted input fields

I'm automating e2e tests with Protractor on an angular app.
However, I have an issue when sending keys on input fields.
The sendKeys would miss few characters everytime so I found a workaround :
static sendKeys(value, element){
value.split('').forEach((c) => element.sendKeys(c));
}
This works well but it takes more than 3 times the time the original sendKeys function would.
Well no problem my tests are still functionnal right ?
My app now has new fields with scripts behind them.
One of them is a datepicker input, you can either choose from the datePicker or type it manually. However, for today's date you would type 09022018 and the slashes are automatically appended at the right place (like so 09/02/2018). If you were to enter a wrong date the field is cleared.
Now back to the problem : it seems that both my implementation of sendKeys and the original one loose focus after each submitted key. This means that I can't enter a valid date in the input field as it's cleared after each simulated keypress.
I could use browser.executeScript to fix it but I wouldn't be able to test the functionnality adding slashes. Also, as you type, the datepicker is still open and refreshes after each keypress, you can select a date from it at any time and that is also a feature I want to test.
Thanks in advance
Use executeScript to set the date in backgrond, then use sendKeys to enter a space or Tab at the end to trigger the Keyborad event which will check the input and format the input with slash
function enterDate(date) {
var script = 'arguments[0].value=arguments[1]';
// input box for date
var dateBox = element(by.xxx(yyy));
browser.executeScript(script, dateBox, date);
dateBox.sendKeys(" ");
// or try send Tab
dateBox.sendKeys(protractor.Key.TAB);
}
enterDate('09022018');
You can try this solution on other fields you fixed but take 3 more time.

How to identify webelement using partial attribute of id?

I have to find xpath for a textbox using id attribute. However, a portion of the attribute keeps changing every time I login to the application which I'm automating and the remaining portion remains unchanged. PFB example -
Attribute ------> id="StringJob_value_1102199569"
Here, the numeric value changes during every login and the portion "StringJob_value" remains unchanged.
Hence, is there any way in selenium to only use the constant portion of the attribute to identify the web element(Text Box)?
Try the following xpath:
//*[contains(#id, 'StringJob_value_')]

How to insert validation in datepicker interactive report in apex5.0

I have one field :P2_DATE, datepicker on an interactive report in apex5.0.
First Question:
How can i create validation thru:
1. A dynamic action
2. A validation process
that gives an error msg: 'Date should not be greater than system date'
when user choose from datepicker.
Second Question:
How to show only today's date in the date picker and disable others dates.
Pls provide steps-by-steps instruction if possible...thxs!!
Add Validation
Set type to PL/SQL Expression and put:
to_date(:P2_DATE,'DD-MM-YYYY') = to_date(sysdate,'DD-MM-YYYY')
You can see this Answer:jQuery Date Picker - disable past dates for disable dates in datepicker but you already have control over date by validation.
Another way is to create custom datepicker from external plugin.

Bootstrap DatePicker setDate method not updating calendar

I'm setting the value of a bootstrap datepicker by making use of the setValue method provided.
For example
tripToDatePicker.setValue(tripFromDatePicker.date);
But for some reason the calendar is not updated
'setValue' is replaced by 'setDate'.
Using a string as input for setDate can be tricky. It has to match with the dateformat, else you can get unexpected results. It is more safe to create a 'new Date(y,m,d)' from your input, e.g. new Date(2015,3,10) for '10 Apr 2015'. This will always work.
When using a date representation in seconds, e.g. 1428659901, then use 'new Date(value*1000)'. Note that datepicker will eat any value here, but only show the selected date in the calendar if hours, minutes and seconds are equal to 0. Took me a while to figure that out....
Edit:
http://www.eyecon.ro/bootstrap-datepicker/ is not much documented, you should try http://eternicode.github.io/bootstrap-datepicker/.
anyway the code below will work for you
$("#dp1").datepicker("update", "02-16-2012");
or
$("#dp1").datepicker("setValue", "02-17-2012");
where "#dpi" is the id of the text field on whcih datepicker is used.
After trying many things, I ended up using "update" method. The $("#dp1").datepicker("update", "02-02-2012") or $("#dp1").datepicker("update", "02/02/2012") works for me. Surprisingly no document about this method at author website. Thanks.