Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Date Field prevents past dates

Guest
May 19, 2016 May 19, 2016

I have crated a form that employees use to move products to another department.  On that field is the expiration date of the product.  I want to crate a field that when the user puts in a previous date (i.e today is 5/19/16 and they put in 5/18/16) the field either turns red or a message box opens up indicating the product has expired.  Thanks

TOPICS
Acrobat SDK and JavaScript , Windows
538
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 19, 2016 May 19, 2016

You can use a custom Validate script for the text field, something like the following:

// Validate script for text field

(function () {

    // Do nothing if the field is blank

    if (!event.value) {

        return;

    }

    // Get the current date/time

    var oDate = new Date();

    // Set the time of today's date to midnight

    oDate.setHours(0, 0, 0, 0);

    // Convert field entry to date object

    // Use whatever date format the field is up for

    var oDateEntered = util.scand("m/d/yyyy", event.valu

...
Translate
LEGEND ,
May 19, 2016 May 19, 2016

You can use a custom Validate script for the text field, something like the following:

// Validate script for text field

(function () {

    // Do nothing if the field is blank

    if (!event.value) {

        return;

    }

    // Get the current date/time

    var oDate = new Date();

    // Set the time of today's date to midnight

    oDate.setHours(0, 0, 0, 0);

    // Convert field entry to date object

    // Use whatever date format the field is up for

    var oDateEntered = util.scand("m/d/yyyy", event.value);

    if (+oDateEntered < +oDate) {

        // Alert the user

        app.alert("Please enter a date that is not in the past.", 3);

        // Optionally, reject the entry

        event.rc = false;

    }

})();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 20, 2016 May 20, 2016
LATEST

Thank you so much.  It works great and doesn't get upset with a reset form button.  Thank you so much.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines