Page 1 of 1

Adding days to date field in a launch form

Posted: Sun Dec 12, 2021 8:19 am
by yvesf
I have got a field in a launch form called 'acc_date'. I have initialize the date on the event onnuload with nuSetDate('acc_date');
I would like to add a button to change the value of acc_date by adding 1 or more days. How can I do that ? Is there a nu JavaScript that is allowing me to perform this operation behind onclick event of the button ? Many thanks.

Re: Adding days to date field in a launch form

Posted: Sun Dec 12, 2021 8:41 am
by kev1n
Add this function to the form's Custom Code:

Code: Select all

function addDaysToDateObject(i, days) {
	let o = $('#' + i);
	let d = nuFORM.removeFormatting(o.val(), o.attr('data-nu-format'));
	nuSetDateValue(i ,new Date(d).addDays(days));
}
And in the button's onclick event:

Code: Select all

addDaysToDateObject('acc_date',4);

Re: Adding days to date field in a launch form

Posted: Sun Dec 12, 2021 11:10 am
by yvesf
Thanks Kevin. It works except that the value doesn't stay in the acc_date field. How to ensure that the field will keep the new value ?
Thx

Re: Adding days to date field in a launch form

Posted: Sun Dec 12, 2021 11:30 am
by kev1n
Normally the value should stay in the field using the latest version.

Otherwise, add o.change(); after
nuSetDateValue(...)

Re: Adding days to date field in a launch form

Posted: Sun Dec 12, 2021 12:18 pm
by yvesf
I have taken the last version yesterday.
o.change() doesn't change anything unfortunately.
If you have another idea...Thx

Re: Adding days to date field in a launch form

Posted: Sun Dec 12, 2021 1:13 pm
by yvesf
I think it is due to the nuFilter activated on change on this field.

Re: Adding days to date field in a launch form

Posted: Sun Dec 12, 2021 1:49 pm
by kev1n
I cannot replicate the issue here. If I understand it right, the object acc_date is on the main form and has an onchange event that refreshes the iframe
by calling nuFilterRun() ?

Re: Adding days to date field in a launch form

Posted: Mon Dec 13, 2021 3:09 pm
by yvesf
That's correct Kevin. On change event, I execute the nuFilterRun(). When I click on the button on which I change the date, I see few seconds the new date but it disappears and become empty.

Re: Adding days to date field in a launch form

Posted: Mon Dec 13, 2021 4:04 pm
by kev1n
It looks like your launch form is refreshed somehow. Are you calling nuGetBreadcrumb() somewhere?

I created a small demo (Launch form with date filter). Click on the [+] button to increment the date in the input and filter the iframe Browse form by that date. The date does not appear after the refresh.

https://test.nubuilder.cloud?f=61b75a13 ... t&p=nutest

You can inspect the objects, forms etc. and perhaps you can make out a difference.