Page 1 of 2

Datetime-Local - not displayed after saving

Posted: Tue Feb 06, 2018 2:53 pm
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?

Re: Datetime-Local - not displayed after saving

Posted: Wed Feb 07, 2018 3:20 am
by toms
Here is a short video: https://vimeo.com/254608248

Re: Datetime-Local - not displayed after saving

Posted: Sat Feb 10, 2018 8:40 am
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.

Re: Datetime-Local - not displayed after saving

Posted: Sun Feb 11, 2018 11:19 am
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;
};

Re: Datetime-Local - not displayed after saving

Posted: Sun Feb 11, 2018 7:47 pm
by admin
toms,

I have made a change and uploaded it to Github.

I think it should work fine now.

Steven

Re: Datetime-Local - not displayed after saving

Posted: Sun Feb 11, 2018 8:20 pm
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

Re: Datetime-Local - not displayed after saving

Posted: Sun Feb 11, 2018 9:35 pm
by admin
toms,

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

But it works ok for me now.

Steven

Re: Datetime-Local - not displayed after saving

Posted: Mon Feb 12, 2018 6:32 am
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.

Re: Datetime-Local - not displayed after saving

Posted: Mon Feb 12, 2018 9:34 am
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

Re: Datetime-Local - not displayed after saving

Posted: Tue Oct 09, 2018 3:33 am
by Rolf
why not use functions built into MySQL/MariaDB for this? I went this way and it's magnitudes of orders simpler.