Bootstrap DatePicker setDate method not updating calendar - twitter-bootstrap-3

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.

Related

vaadin flow DateTimePicker returns null if only one field entered

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

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 set string to datetime widget?

The title is self explanatory. I am having difficulties setting a string value to a date time widget.
XCP has a build in function stringToDate
which i use in these examples...
1. stringToDate('5-5-2009')
2. stringToDate('05-05-2009')
3. stringToDate('5/5/2009')
But non of them work. What am I missing here ?
Also i set the value of the widget in the behaviors tab of the date widget.
If you are talking about Date-Time Input widget then you need to use dateToString not stringToDate.
I figured out the issue. It's dependent to the format in which you save your date to string value. If we save the Date-Time Input widget value in this format:
dateToString('12-12-2018', 'm-d-Y')
then doing a :
stringToDate(savedvalue) will work only when the format saved was 'm-d-Y'. It wasn't working before because i saved it as 'd-m-Y'.

Bootstrap 3 - DateTimePicker - Can time portion be ignored?

I'm using the Bootstrap 3 DateTimePicker. When the user tabs into a field using this component, the current date and time is automatically entered. In some cases this is what I want. However, there are other times I want the component to completely ignore the time portion and not entered by default in a field. I can't seem to find a way to do this.
This will only display the date by default, try and see
$('.future');.datetimepicker({
pickTime: false,
format: 'DD/MM/YYYY'
});

Xpages djCurrencyTextBox with fractional=false

Since clean 8.5.3 Domino has problem with localized numbers with space as thousand separators, I decided to switch to djCurrencyTextBox. But as don't want to display fractional part, I'm struggling with it too. Even on 9.0.1 test server.
If I create simple field using:
<xe:djCurrencyTextBox id="djCurrencyTextBox1" value="#{document1.currency}">
<xe:this.constraints>
<xe:djNumberConstraints fractional="false">
</xe:djNumberConstraints>
</xe:this.constraints>
</xe:djCurrencyTextBox>
It does not recognize any number entered. ( I get message that value is not valid even when I enter just 1)
When add it as dojo attribute directly, it works as expected
<xe:djCurrencyTextBox id = "djCurrencyTextBox1"
value ="#{document1.currency}" >
<xe:this.dojoAttributes>
<xp:dojoAttribute name ="data-dojo-props"
value ="constraints:{fractional:false}" >
</xp:dojoAttribute>
</xe:this.dojoAttributes>
</xe:djCurrencyTextBox >
Any ideas what can cause the issue?
This is a known issue that is not fixed in 9.0.1
Using the first example above, no matter what value you set on the fractional constraint (enable/disable/auto/true/false), the textbox only ever accepts a value with fractional part included (e.g. 567.89), which is incorrect for disable & false values. The second example works as expected with fractional set to true or false.
This is because, looking at the page source, the html output for the first example is:
<input dojoType="dijit.form.CurrencyTextBox" constraints="{"fractional":"false"}" id="view:_id1:djCurrencyTextBox1" name="view:_id1:djCurrencyTextBox1">
The """ parts should not be included in the constraints.
Whereas with the 2nd example, there is no such issue:
<input dojoType="dijit.form.CurrencyTextBox" data-dojo-props="constraints:{fractional:false}" id="view:_id1:djCurrencyTextBox2" name="view:_id1:djCurrencyTextBox2">
As this has not yet been fixed in 9.0.1, all you can do is utilise the workaround that you have posted for the time being.
UPDATE: The fix for this issue is in Release 9 of the v901 XPages Extension Library on OpenNTF