Javascript to Make an Autofill Editable

Explorer ,
Mar 04, 2021 Mar 04, 2021

Copy link to clipboard

Copied

I posted this somewhere else here and I didn't get the help that I needed so I'm hoping that posting it a different section might get me a bit more range.  Hope that this is okay.

I am creating a form with multi-pay options available.

I would like the first payment amount ("Amount To Be Paid on First Card") to autofill with the total amount but be editable if the total amount ("Amount To Be Paid") is to be split.  In that event, I would also like other fields ("Amount To Be Paid on Second Card") to become required if the first amount is lesser than the total amount.

I am entering the following code into the Amount To Be Paid on First Card custom calculation script field.

It pulls the auto fill, it makes the secondary payment field required, but it does not allow the amount to be changed from the autofill of the total amount.

I know that my script has conflicts.  I'm instructing it to copy information and to make fields required in the event that the amount in the second field is lesser than the amount in the above.

I'm not knowledgable enough to figure out how to instruct it to bypass the autofill if it is changed by the user; so, even if I were to type an amount into the first card's amount to be paid feild, it readjusts and autopopulates with the data from the first field.

I am still learning (mostly from this community) and would appreciate any help that can be offered.  My attempt is below.  Thank you for any assistance.

event.value = this.getField("Amount To Be Paid").value;

var n = this.getField("Amount To Be Paid On First Card").value;

if (n < "Amount To Be Paid On First Card") {
	testMyField(event.value, "Amount To Be Paid On Second Card");
}
TOPICS
How to, JavaScript, PDF forms

Views

144

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

correct answers 1 Correct Answer

Adobe Community Professional , Mar 05, 2021 Mar 05, 2021
If you choose that way you will also need custom format script for currency, instead just use this as validation script of "Amount to be paid" field: this.getField("Amount To Be Paid on First Card").value = event.value; That way you can set format easy, and use this as calculation script of  "Amount To Be Paid on Second Card" to set "Amount To Be Paid on Second Card" required when "Amount To Be Paid on First Card" is less then "Amount to be paid":if(Number(this.getField("Amount To Be Paid on Fir...

Likes

translate

Translate

Translate
Engaged ,
Mar 04, 2021 Mar 04, 2021

Copy link to clipboard

Copied

Who gave you that code?

Where in your code are you making field required?

Why are you using this:

(n < "Amount To Be Paid On First Card")

What are you trying to achive with it?

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
Explorer ,
Mar 04, 2021 Mar 04, 2021

Copy link to clipboard

Copied

This is me frankencodeing a bunch of stuff together.

 

Line 1 is asking it to duplicate the data in "Amount To Be Paid" in the "Amount To Be Paid On First Card" field.

 

Line 2 was the variation instruction to recognize that 'n' equals the next request.

 

The IF statement was intended to have it as if Amount To Be Paid On First Card is less then (or not equal to, but I wanted it to work before I started trying variants) Amount To Be Paid to ┐

 

Line 4 'testMyField(event.value, "Amount To Be Paid On Second Card");' and make that field required.

 

Buuuuut, like I said, I have no idea what I'm doing and it almost worked.  When I input $1000 into Amount To Be Paid, it autofilled Amount To Be Paid on First Card.  That immediately made Amount To Be Paid on Second Card required.

 

It was taunting me!  I'm sure of it.  

 

But can you help?   🙂 

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
Participant ,
Mar 04, 2021 Mar 04, 2021

Copy link to clipboard

Copied

event.value = this.getField ("Amount To Be Paid"). value;
var n = this.getField ("Amount To Be Paid On First Card"). value;

 

I propose another construction assigned to the "Amount To Be Paid" frame:
if (event.value) {// or if (event.willCommit) {
this.getField ("Amount To Be Paid On First Card"). value = event.value;
...
}
changing the value in "Amount To Be Paid" will write this value to the frame "Amount To Be Paid On First Card"

the if command ... means nothing. n (NUMBER) is greater than "Amount To Be Paid On First Card" (string, TEXT). What are you comparing here?
When you assign a value using an event, you get the same values in both frames

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
Engaged ,
Mar 05, 2021 Mar 05, 2021

Copy link to clipboard

Copied

If "Amount To Be Paid on First Card" is less then ""Amount To Be Paid" you want ", "Amount To Be Paid on Second  Card" to become required?

Problem is if "Amount To Be Paid on First Card" populates from "Amount To Be Paid"  it will always be same,

Script can't read your mind, you need to have some sort of switch(button,checkbox...) to stop calculation and enter value manually when you want to split.

 

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
Participant ,
Mar 05, 2021 Mar 05, 2021

Copy link to clipboard

Copied

OK.

But how does the script know that this amount is lower?

Where is the "right" amount that the script can compare the "Amount To Be Paid on First Card"?

In some price base?

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
Explorer ,
Mar 05, 2021 Mar 05, 2021

Copy link to clipboard

Copied

These are all the questions that I was asking myself as well.

 

Ultimately my goal is to do exactly what you guys have described.

 

I would like for the document to be a multipay document where the Amount To Be Paid auto fills into the Amount To Be Paid On First Card.  If there is no change to be made there, then the user carries on and fills out the rest of the payment details.  However, if the amount is not to remain the same, I was hoping for the autofill to be editable and override the autofill, at which point the manual input would make it less than the Amount To Be Paid field.  That difference would trigger the payment details for the second payment to become required before the file could be saved and mailed out for completion.

 

But the response from you two, is actually matching the response that I got from the first posting that I made, where the suggestion is to make a checkbox or a button to create a trigger allowing for the fields to become necessary...  I was hoping to avoid that because, as it stands now, the only things in my document are fillable fields and dropdown menus.  But having three people tell you the same things makes you are start to rethink your stance.  Lol

 

I really appreciate your help with this.  Thank you so much.

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
Participant ,
Mar 05, 2021 Mar 05, 2021

Copy link to clipboard

Copied

View the attached pdf.
the field with the green border is the "parent" field.
when you write a value in it, it will be "copied" to the field with a red border.
but in the "red" field you can enter any value "overwriting" the one that was imposed by the "green" field.
was that what you meant?

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
Explorer ,
Mar 05, 2021 Mar 05, 2021

Copy link to clipboard

Copied

That is exactly what I meant!  Are you about to become my hero?

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
Participant ,
Mar 05, 2021 Mar 05, 2021

Copy link to clipboard

Copied

a small fix 🙂
when you type something in the "green" field, the same will appear in the "red" field.
BUT when you type something in the "red" field, the "green" field will be cut off from the "red" field; both fields become independent

 

maybe it will be useful to you
Good luck

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
Explorer ,
Mar 05, 2021 Mar 05, 2021

Copy link to clipboard

Copied

Okay.  One more request.  Can you break down the code for me?  This is super complicated to my lamen eyes...  I really want to understand what I'm putting in practice.  🙂

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
Adobe Community Professional ,
Mar 05, 2021 Mar 05, 2021

Copy link to clipboard

Copied

If you choose that way you will also need custom format script for currency, instead just use this as validation script of "Amount to be paid" field:

 

this.getField("Amount To Be Paid on First Card").value = event.value;

 

That way you can set format easy, and use this as calculation script of  "Amount To Be Paid on Second Card" to set "Amount To Be Paid on Second Card" required when "Amount To Be Paid on First Card" is less then "Amount to be paid":

if(Number(this.getField("Amount To Be Paid on First Card").value) < Number(this.getField("Amount To Be Paid").value))
event.target.required = true;
else event.target.required = false;

 

 

EDIT: fixed code.

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
Explorer ,
Mar 05, 2021 Mar 05, 2021

Copy link to clipboard

Copied

So many heroes!!!!! *-*

I'm going to try all of these tomorrow and see about making this sitch work.  You guys are rock stars.  Thank you so much for the use of your brains.  ❤️

 

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
Participant ,
Mar 05, 2021 Mar 05, 2021

Copy link to clipboard

Copied

interesting solution, Nesa 🙂

Shelby, in the attached pdf you can take a close look at how it works
the video illustrates the value transfer mechanism

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
Participant ,
Mar 05, 2021 Mar 05, 2021

Copy link to clipboard

Copied

a short presentation where the individual scripts are

 

good luck

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