Welcome to the nuBuilder Forums!

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

[JavaScript] nuBeforeSave (two issues)

Questions related to using nuBuilder Forte.
Post Reply
pyro
Posts: 11
Joined: Wed Jan 17, 2018 7:06 pm

[JavaScript] nuBeforeSave (two issues)

Unread post by pyro »

Hi,

I have a very strange behavior in my code.

If I add nuBeforeSave (even empty) it my page does not save
If I remove nuBeforeSave it does safe but sn_datetime is just 0000-00-00 00:00:00 whereas if I use nuBeforeSave it fills the correct date (e.g 2018-01-22 14:32:36).

Maybe also worth mentioning is if I have the "0000-00-00 00:00:00" issue it actually shows me the correct date in the field for about half a second before changing back to "0000-00-00 00:00:00" and save it.

I am sure the are two diffent issues, however they seem to be linked in my case.


Code: Select all

function nuOnClone() {
     $('#sn_sn').val('');
     $('#sn_sn').focus();
}

function checkchange() {
if ($('#sn_sn').val().length != 10) {   
     alert('This is not a Serial Number');
     $('#sn_sn').val('');
     return;
}

now = new Date().toISOString().slice(0, 19).replace('T', ' ');
$('#sn_user').val(nuAccessLevelCode());
$('#sn_datetime').val(now);

nuSaveAction();
setTimeout(function(){ nuCloneAction(); }, 2000);

}

function nuBeforeSave(){
}
checkchange if called as an onchange event
same layout as -> https://forums.nubuilder.cloud/viewtopic.php?f=19&t=9243
I just update unBuilder today from git hub.

thank you for your great help so far
BR
Moritz
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: [JavaScript] nuBeforeSave (two issues)

Unread post by toms »

Moritz,

I'm not sure what the default return value of the nuBeforeSave() function is.
Does it help adding

Code: Select all

 return true;
in that function?
pyro
Posts: 11
Joined: Wed Jan 17, 2018 7:06 pm

Re: [JavaScript] nuBeforeSave (two issues)

Unread post by pyro »

Hi Tom,

thank you that did the trick.

Now there is just the issue with with the date field left if I do not call the nuBeforeSave funktion. I it seems to be the same issue as https://forums.nubuilder.cloud/viewtopic.php?f=19&t=9256
Last edited by pyro on Tue Jan 23, 2018 3:06 am, edited 1 time in total.
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: [JavaScript] nuBeforeSave (two issues)

Unread post by admin »

pyro,

Here is a Input:nuDate Object...
date_format.PNG
To manually add a date you will need to add it in the format that the Object has been set to.

eg.

Code: Select all

$('#sn_datetime').val('2014/Feb/11').change();
Steven
You do not have the required permissions to view the files attached to this post.
pyro
Posts: 11
Joined: Wed Jan 17, 2018 7:06 pm

Re: [JavaScript] nuBeforeSave (two issues)

Unread post by pyro »

Hello Steven,

$('#sn_datetime').val(now').change();

Helped me a lot thank you. However there still seems to be wired behavior about the datetime.
It seems that I need $('#sn_datetime').val('0000-00-00 00:00:00').change(); to initialize the field. If I don't use it the first time I save the form it will change the field back to "0000-00-00 00:00:00". But for further submits it will work.

It only works reliable when I use the following code:

Code: Select all

function nuOnClone() {
     $('#sn_sn').val('');
     $('#sn_sn').focus();
}

function checkchange() {
if ($('#sn_sn').val().length != 10) {   
     alert('This is not a Serial Number');
     $('#sn_sn').val('');
     return;
}

now = new Date().toISOString().slice(0, 19).replace('T', ' ');

if (nuAccessLevelCode()==='') {   
$('#sn_user').val('admin').change();
} else {
    $('#sn_user').val(nuAccessLevelCode()).change();
}

$('#sn_datetime').val('0000-00-00 00:00:00').change();
$('#sn_datetime').val(now).change();

nuSaveAction();
setTimeout(function(){ nuCloneAction(); }, 1000);

}

function nuBeforeSave(){
if ($('#sn_sn').val().length != 10) {   
     alert('This is not a Serial Number');
     $('#sn_sn').val('');
     return;  
}

return true;
}

my database and nuBuilder setting:
datetime nubuilder.PNG
datetime phpmyadmin.PNG
Thank you
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: [JavaScript] nuBeforeSave (two issues)

Unread post by toms »

pyo,

Would it work with a nuDate Input Type?
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: [JavaScript] nuBeforeSave (two issues)

Unread post by admin »

pyro,

If you do what toms said, it should work fine. It did here for me...
date_format.PNG
Steven
You do not have the required permissions to view the files attached to this post.
Post Reply