Hello,
I've looked at the code library on how to add days to dates but can't figure it out.
https://github.com/nuBuilder/nuBuilder- ... t_add_days
I've had more success with the php way of adding date to records after the form is entered and the record is saved. However I now need to do this on the form using JS before commiting the record.
Why?
I have a form for solution preparation. It can pull through various bits of reference information fro the solution being made via a lookup, and copy that information into the form (so that for future the reference information used to make the solution is there, and if the recipe changes in the future it won't alter the old records).
On my form for solution preparation I have a *prepared_on* date field. Once populated it should trigger and populate the *calc_expiry* date field, which is achieved by adding the *prepared_on* field and a number in days from another field *shelf_life*. The *shelf_life * field infomation is pulled through via a lookup to the substance being prepared and copied into the prep form.
If the calculated expiry is correct, then a button press by the user will copy that information to an "expires_on* field. If the calculated expiry is incorrect (such as a solution ingredient having a short shelf life) then the corret date can be added manually.
I've run nuHash and it looks like the fields are avaiable as hash cookies.
Is there a way to get this workflow to work in nuBuilder? or are the date calculation differences between sql/php and js going to cause issues?The previosu code I had worked in php but not sure how to translate that to JS to use the oninput events to trigger the changes.
Thanks,
Paul
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
JS Adding Days to Dates?
-
- nuBuilder Team
- Posts: 4304
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 445 times
- Contact:
Re: JS Adding Days to Dates?
calc_expiry (date) = prepared_on (date) + shelf_life (number of days):
Code: Select all
var oPreparedOn = $('#prepared_on');
var vPreparedOn = nuFORM.removeFormatting(oPreparedOn.val(), oPreparedOn.attr('data-nu-format'));
d = new Date(vPreparedOn);
var vExpiry = d.addDays(Number($('#shelf_life').val()));
$('#calc_expiry').val(vExpiry).change();
Re: JS Adding Days to Dates?
Hi kev1n,
I've tried putting this code on the form, and also in the prepared date input as a oninput event but neither seems to trigger the code to work. Is there something I'm missing?
I've tried putting this code on the form, and also in the prepared date input as a oninput event but neither seems to trigger the code to work. Is there something I'm missing?
-
- nuBuilder Team
- Posts: 4304
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 445 times
- Contact:
Re: JS Adding Days to Dates?
Try replacing this line:
with:
Code: Select all
$('#calc_expiry').val(vExpiry).change();
Code: Select all
nuSetDateValue('calc_expiry',vExpiry);
You do not have the required permissions to view the files attached to this post.