Welcome to the nuBuilder Forums!

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

Datetime-Local - not displayed after saving Topic is solved

Questions related to using nuBuilder Forte.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Datetime-Local - not displayed after saving

Unread post by toms »

Hi,

Has anyone managed to setup a Datetime-Local object field so that its changed value is displayed again after saving the record?

Setup:

- An object of type: Input, Input Type : Datetime-Local
- db data type: datetime (or timestamp)

1. First enter a date/time:
datetimelocal.png
2. Save the form

3. Result: The field reverts back to its original state:
datetimelocal_reverted.png
Looking at the db table, the datetime value has been correctly stored. But when I go back to the Browse Form and open that record again, the Datetime-Local field is still empty (respectively showing mm/dd/yyy...)

Am I missing something?
You do not have the required permissions to view the files attached to this post.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Datetime-Local - not displayed after saving

Unread post by toms »

Here is a short video: https://vimeo.com/254608248
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Datetime-Local - not displayed after saving

Unread post by toms »

Hi,

I've tried to isolate the source of the problem by inspecting the datetime-local object f.objects in nuBuildEditObjects();

It's value is correctly stored as:
value = "2018-12-30 10:10:00"

But its format is empty:
format = "";

Consequently (this is what I think), no value is applied in addFormatting(); because its format is empty.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Datetime-Local - not displayed after saving

Unread post by toms »

I worked out a fix. Can you check if it works for you too?

nuForm.js (624)

Code: Select all

	if(input_type != 'file'){
        if(input_type == 'datetime-local'){  // added
			var d = new Date(w.objects[i].value); // added
        	$('#' + id).val(toDatetimeLocal(d))  // added
        }else if(input_type == 'button'){
			$('#' + id).val(nuTranslate(w.objects[i].value))
		}else{
			$('#' + id).val(nuFORM.addFormatting(w.objects[i].value, w.objects[i].format));
		}
	}


And the function to convert to datetime-local format:

Code: Select all

function toDatetimeLocal(d) {
    var
        YYYY = d.getFullYear(),
        MM = nuPad2(d.getMonth() + 1),
        DD = nuPad2(d.getDate()),
        HH = nuPad2(d.getHours()),
        II = nuPad2(d.getMinutes()),
        SS = nuPad2(d.getSeconds());
    return YYYY + '-' + MM + '-' + DD + 'T' + HH + ':' + II; // + ':' + SS;
};
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Datetime-Local - not displayed after saving

Unread post by admin »

toms,

I have made a change and uploaded it to Github.

I think it should work fine now.

Steven
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Datetime-Local - not displayed after saving

Unread post by toms »

Steven,

It works like that but a warning is displayed when the value is "0000-00-00 00:00:00"
datetime_local_invalid.PNG
You do not have the required permissions to view the files attached to this post.
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Datetime-Local - not displayed after saving

Unread post by admin »

toms,

That was happening to me as well before the latest Github update.

But it works ok for me now.

Steven
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Datetime-Local - not displayed after saving

Unread post by toms »

Steven,

Don't you see a warning message in the console when no datetime value has been entered in the field? (tested with different nuBuilder instances)
Normally you should since the
value "0000-00-00T00:00:00" does not conform to the required format.
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Datetime-Local - not displayed after saving

Unread post by admin »

toms,

I originally tested it in the console using jQuery, to find out why it wasn't working.

That's why I have seen that message.

Its fixed though in nuBuilder now (from what I figured out using the console).

If you do something like $('#thedateandtime').val("0000-00-00T00:00:00"), in the console, you will still get the same message.

But that has nothing to do with nuBuilder.

When a nuBuilder Forte Form is opened a date/time field is now displayed and I see no message,

It loads the value properly now, which it didn't originally when you found the bug.


Steven
Rolf
Posts: 28
Joined: Fri May 20, 2016 9:24 am

Re: Datetime-Local - not displayed after saving

Unread post by Rolf »

why not use functions built into MySQL/MariaDB for this? I went this way and it's magnitudes of orders simpler.
Post Reply