Timesheet - Validation script

New Here ,
Sep 05, 2018 Sep 05, 2018

Copy link to clipboard

Copied

Dear Community,

I wondered if you could help me.

I am trying to add a validation rule for some fields in the PDF timesheet created as a fillable form.

The employee have an option to select from 0, 0.25,0.50,0.75 and 1 day from a drop-down in the three columns:

1. Standard hours

2. Sick Day

3. Day off

What we would like to achieve is to restrict the total value of these three column to maximum 1 meaning that our employee can only claim up to 1 day for each working day regardless the column filled.

I have tried to build the validation rule with the below using the column SET with a value "1"

(function () {

    var v1 = +getField("SET1").value;

    var v2 = +event.value;

    if (v2 > v1) {

        app.alert("The total value per day must not exceed 1", 1);

         event.rc = false;

    }

if (v2 < v1) {

        app.alert("Please assign Sickness Absence or Annual Leave for the remainder of this working day. The rest days for the part-time workers are specified in Day Off column. ", 1);

         event.rc = false;

    }

})();

The problem I am facing at the moment is that 25 fields in the form is validated in one go so the users gets 25 error messages before even gets a chance to select a value in the relevant field.

Could we assign a script some kind of level or priority?

Many thanks.

Veronika

[Question moved to the Acrobat JavaScript forum from the Reader forum. -Mod.]

TOPICS
Acrobat SDK and JavaScript

Views

203

Likes

translate

Translate

Translate

Report

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
Most Valuable Participant ,
Sep 05, 2018 Sep 05, 2018

Copy link to clipboard

Copied

Let's try to simplify this problem. Say you have three drop-down fields with those values, called Dropdown1 to Dropdown3.

You can use this function as a doc-level script and then call it from the custom Validation event of each one of those fields to achieve what you've described:

function validateDropDownsTotal() {

    var maxAllowedValue = 1;

    var allFields = ["Dropdown1", "Dropdown2", "Dropdown3"];

    var total = Number(event.value);

    for (var i in allFields) {

        if (event.target.name==allFields) continue;

        total+=Number(this.getField(allFields).valueAsString);

    }

    if (total>maxAllowedValue) {

        app.alert("Error!");

        event.rc = false;

    }

}

Likes

translate

Translate

Translate

Report

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
New Here ,
Sep 07, 2018 Sep 07, 2018

Copy link to clipboard

Copied

Many thanks, you have been very helpful.

I have a question number 2 regarding the overtime to be assigned to different fields.

I am trying to build an overtime form to calculate the overtime hours with the layout below:

Standard weekly hours

O/T start     OT/finish     OT@1.00     OT@1.50     OT@2.00    

What we are trying to achieve is to calculate the overtime and have it assigned into the relevant OT field taking into the consideration a weekly standard hours.

Standard working week: 37.50 hours    

Employee selects the date.

if it falls down on weekday, overtime hours are calculated and displayed in OT@1.50 column

If it falls down on weekend, overtime hours are calculated and displayed in OT@2.00 column    

If standard hours are less than 37.50 hours then OT hours will be calculated and displayed in OT@1.00 until the value reaches 37.50, then the whole process above starts again.

If we could have this built, it would make life so much easier.

Look forward to hearing from you.

Likes

translate

Translate

Translate

Report

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
Most Valuable Participant ,
Sep 07, 2018 Sep 07, 2018

Copy link to clipboard

Copied

Sorry, this goes a bit beyond what I'm willing to do for free... If you're interested in hiring someone to do it for you you can contact me at try6767 at gmail.com to discuss it further.

If you wish to write the code yourself I recommend these tutorials:

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-2

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-3

JavaScript Date Reference

Likes

translate

Translate

Translate

Report

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