Welcome to the nuBuilder Forums!

Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.

Current date field

Questions related to using nuBuilder Forte.
Post Reply
Olikun
Posts: 68
Joined: Tue Mar 09, 2021 6:45 pm

Current date field

Unread post by Olikun »

Hello,

a new question from me.

I would like to have a field in which the current date is displayed.

How do I do that?


:)
kev1n
nuBuilder Team
Posts: 4565
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 76 times
Been thanked: 529 times
Contact:

Re: Current date field

Unread post by kev1n »

Code: Select all

function setInputDate(id, d) {

    if (typeof d === 'undefined') {
        var d = new Date();
    }

    var df = d.getFullYear() + '-' + nuPad2(d.getMonth() + 1) + '-' + nuPad2(d.getDate());
    var obj = $('#' + id);
    var format = obj.attr('data-nu-format');
    obj.val(nuFORM.addFormatting(df, format)).change();
  
}
Call this in your form's Custom Code to populates your date field with the current date when the form is loaded:

Code: Select all

setInputDate('your_date_object_ID');
Olikun
Posts: 68
Joined: Tue Mar 09, 2021 6:45 pm

Re: Current date field

Unread post by Olikun »

I entered the long code in my form (custom code)


where do I put this line?

Code: Select all

setInputDate
kev1n
nuBuilder Team
Posts: 4565
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 76 times
Been thanked: 529 times
Contact:

Re: Current date field

Unread post by kev1n »

Also there
Olikun
Posts: 68
Joined: Tue Mar 09, 2021 6:45 pm

Re: Current date field

Unread post by Olikun »

mhh it doesn't work: /

I put exactly that in the form code here

Code: Select all

// aktuelles Datum - START


function setInputDate(id, d) {

    if (typeof d === 'undefined') {
        var d = new Date();
    }

    var df = d.getFullYear() + '-' + nuPad2(d.getMonth() + 1) + '-' + nuPad2(d.getDate());
    var obj = $('#' + id);
    var format = obj.attr('data-nu-format');
    obj.val(nuFORM.addFormatting(df, format)).change();


// aktuelles Datum - ENDE


setInputDate('lieferdatum');

The field is called delivery date

It's an nDate field (dd-mm-yy)
kev1n
nuBuilder Team
Posts: 4565
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 76 times
Been thanked: 529 times
Contact:

Re: Current date field

Unread post by kev1n »

There's a } missing at the end of the function. See my code above.

PS: There's now a nuSetDateValue() function in nuBuilder.
Olikun
Posts: 68
Joined: Tue Mar 09, 2021 6:45 pm

Re: Current date field

Unread post by Olikun »

it works now

thanks
Olikun
Posts: 68
Joined: Tue Mar 09, 2021 6:45 pm

Re: Current date field

Unread post by Olikun »

Another question about that

The code works fine

Code: Select all

// aktuelles Datum - START


function setInputDate(id, d) {

    if (typeof d === 'undefined') {
        var d = new Date();
    }

    var df = d.getFullYear() + '-' + nuPad2(d.getMonth() + 1) + '-' + nuPad2(d.getDate());
    var obj = $('#' + id);
    var format = obj.attr('data-nu-format');
    obj.val(nuFORM.addFormatting(df, format)).change();
 
}

setInputDate('heutedatum');


// aktuelles Datum - ENDE
Since I inserted the code, I always get a message when I leave the form.
when I save the Form comes anyway.
The message is not from nuBuilder. It's from the browser

Image


If I remove the code, the message no longer comes
kev1n
nuBuilder Team
Posts: 4565
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 76 times
Been thanked: 529 times
Contact:

Re: Current date field

Unread post by kev1n »

Add nuHasNotBeenEdited(); after setInputDate('heutedatum');
Post Reply