Welcome to the nuBuilder Forums!

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

Default value for object

Questions related to using nuBuilder Forte.
Locked
danpadro
Posts: 8
Joined: Fri Feb 01, 2013 10:56 am

Default value for object

Unread post by danpadro »

In Nu3 I was set to default value

Code: Select all

SELECT CURDATE ();
or the current user

Code: Select all

SELECT '# nu_user_id #'
and at the opening of the form, we showed the current date or the current user.
For this:
nu31.jpg
Result
nu31.png
and
nu32.jpg
Result
nu32.png
what should i do in Nu4?

thanks.
You do not have the required permissions to view the files attached to this post.
danpadro
Posts: 8
Joined: Fri Feb 01, 2013 10:56 am

Re: Default value for object

Unread post by danpadro »

I've seen something here posted by toms but before I apply .... it's gone. :( anyway...
To get the current date in the form field I put this code in javascript...

Code: Select all

function mysqlDate(date){
    date = date || new Date();
    var dd = date.getDate();
    var mm = date.getMonth()+1;
    var yyyy = date.getFullYear();

if(dd<10) {
    dd='0'+dd
} 
if(mm<10) {
mm='0'+mm 
} 
return dd + "." + mm + "." + yyyy; //--ex. 07.03.2018
}
... then at the event in the object I put this (onfocus)

Code: Select all

$('#day_date').val(mysqlDate());
everything is ok, the field is populated but it is not saved. Save only if I click on the current calendar date.
any suggestion?
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Default value for object

Unread post by admin »

danpadro,

You are nearly there...

Code: Select all

$('#day_date').val(mysqlDate()).change();
nuBuilder only saves fields that have been edited - running change() sets the field property to edited.


Steven
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Default value for object

Unread post by admin »

danpadro,

Here is another alternative...

Code: Select all

var d = new Date();
var f = d.getFullYear() + '-' + nuPad2(d.getMonth() + 1) + '-' + nuPad2(d.getDate());
var n = $('#cus_date').attr('data-nu-format');
var v = nuFORM.addFormatting(f, n);

$('#cus_date').val(v).change();


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

Re: Default value for object

Unread post by toms »

danpadro,

Here is my answer again:

In nuBuilderForte you can set a field's default value with javascript. Check out this related thread:

https://forums.nubuilder.cloud/viewtopic. ... ult#p15692

Example:
nuuser_default.png
Let me know if you have any further questions.
You do not have the required permissions to view the files attached to this post.
danpadro
Posts: 8
Joined: Fri Feb 01, 2013 10:56 am

Re: Default value for object

Unread post by danpadro »

All 3 variants (2 Steven and 1 toms) we tested and worked perfectly !!!
I would come up with an 'IF' for version 2 (Steven) for those who do not want to add the date automatically when it exists (useful when the form exists and just edits). Thanks Steve and toms for help and work done.

Code: Select all

var d = new Date();
var f = d.getFullYear() + '-' + nuPad2(d.getMonth() + 1) + '-' + nuPad2(d.getDate());
var n = $('#cus_date').attr('data-nu-format');
var v = nuFORM.addFormatting(f, n);

if ( $('#cus_date').val() == '0' || $('#cus_date').val() == '' || $('#cus_date').val() == 'undefined' || $('#cus_date').val() == null )

$('#cus_date').val(v).change();
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Default value for object

Unread post by admin »

.
Locked