Page 1 of 1

Current date field

Posted: Mon Apr 26, 2021 3:59 pm
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?


:)

Re: Current date field

Posted: Mon Apr 26, 2021 4:03 pm
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');

Re: Current date field

Posted: Mon Apr 26, 2021 4:27 pm
by Olikun
I entered the long code in my form (custom code)


where do I put this line?

Code: Select all

setInputDate

Re: Current date field

Posted: Mon Apr 26, 2021 4:30 pm
by kev1n
Also there

Re: Current date field

Posted: Mon Apr 26, 2021 4:43 pm
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)

Re: Current date field

Posted: Mon Apr 26, 2021 5:04 pm
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.

Re: Current date field

Posted: Mon Apr 26, 2021 5:18 pm
by Olikun
it works now

thanks

Re: Current date field

Posted: Thu Apr 29, 2021 3:54 pm
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

Re: Current date field

Posted: Thu Apr 29, 2021 4:47 pm
by kev1n
Add nuHasNotBeenEdited(); after setInputDate('heutedatum');