Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Adding days to date field in a launch form

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Adding days to date field in a launch form

Unread post 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.
kev1n
nuBuilder Team
Posts: 4304
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Adding days to date field in a launch form

Unread post 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);
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: Adding days to date field in a launch form

Unread post 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
kev1n
nuBuilder Team
Posts: 4304
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Adding days to date field in a launch form

Unread post by kev1n »

Normally the value should stay in the field using the latest version.

Otherwise, add o.change(); after
nuSetDateValue(...)
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: Adding days to date field in a launch form

Unread post by yvesf »

I have taken the last version yesterday.
o.change() doesn't change anything unfortunately.
If you have another idea...Thx
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: Adding days to date field in a launch form

Unread post by yvesf »

I think it is due to the nuFilter activated on change on this field.
kev1n
nuBuilder Team
Posts: 4304
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Adding days to date field in a launch form

Unread post 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() ?
yvesf
Posts: 315
Joined: Sun Mar 14, 2021 8:48 am
Location: Geneva
Has thanked: 87 times
Been thanked: 11 times

Re: Adding days to date field in a launch form

Unread post 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.
kev1n
nuBuilder Team
Posts: 4304
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Adding days to date field in a launch form

Unread post 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.
Post Reply