Highlighted

Adobe acrobat Form cannot capture "0" while using split() command

Contributor ,
Sep 16, 2020

Copy link to clipboard

Copied

Hi,

I am trying to split a number (with 2 decimalsplace ) and separate them in before decimal and after decimal.

Example:  

.  Text1 :  I have number say  25.68  ,  now i want it to split into two fields so,

Text2 :  it should show 25 

Text3 : it should show 68   ,

everything is working fine.. until when the number after decimal is 00   then it doesnot show correct value;

 

below is my script

for Text2 calculation script :

var mins = this.getField("Text1").valueAsString;

event.value = mins.split(".")[0]

 

for Text3

var mins = this.getField("Text1").valueAsString;

event.value = mins.split(".")[1]

 

is there any other method to split the number where when the number has 00 in its decimal capture the 0 in Text3 .

ok.. thanks NesaNurani and try67   ...

script is working now... as required .. below is the script i used:

 

var mins = Number(this.getField("Text1").value);

var minsParts = mins.toString().split(".");

if (minsParts.length==2) {
minsParts[1];}
else {event.value =event.value = "00"  ;}

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

106

Likes

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

Adobe acrobat Form cannot capture "0" while using split() command

Contributor ,
Sep 16, 2020

Copy link to clipboard

Copied

Hi,

I am trying to split a number (with 2 decimalsplace ) and separate them in before decimal and after decimal.

Example:  

.  Text1 :  I have number say  25.68  ,  now i want it to split into two fields so,

Text2 :  it should show 25 

Text3 : it should show 68   ,

everything is working fine.. until when the number after decimal is 00   then it doesnot show correct value;

 

below is my script

for Text2 calculation script :

var mins = this.getField("Text1").valueAsString;

event.value = mins.split(".")[0]

 

for Text3

var mins = this.getField("Text1").valueAsString;

event.value = mins.split(".")[1]

 

is there any other method to split the number where when the number has 00 in its decimal capture the 0 in Text3 .

ok.. thanks NesaNurani and try67   ...

script is working now... as required .. below is the script i used:

 

var mins = Number(this.getField("Text1").value);

var minsParts = mins.toString().split(".");

if (minsParts.length==2) {
minsParts[1];}
else {event.value =event.value = "00"  ;}

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

107

Likes

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
Sep 16, 2020 0
Adobe Community Professional ,
Sep 16, 2020

Copy link to clipboard

Copied

What format does you use for field "Text3" ?

Likes

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
Reply
Loading...
Sep 16, 2020 0
Contributor ,
Sep 16, 2020

Copy link to clipboard

Copied

no formatting for Text3

Likes

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
Reply
Loading...
Sep 16, 2020 0
Adobe Community Professional ,
Sep 16, 2020

Copy link to clipboard

Copied

Likes

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
Reply
Loading...
Sep 16, 2020 0
Contributor ,
Sep 16, 2020

Copy link to clipboard

Copied

Yes, it works for manually.. but doesnot work when the value is calculated  and then it has 00 in its decimal place

Likes

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
Reply
Loading...
Sep 16, 2020 0
Contributor ,
Sep 16, 2020

Copy link to clipboard

Copied

Any other way method to capture the 00 after decimal when the field is automatic calculated

Likes

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
Reply
Loading...
Sep 16, 2020 0
Adobe Community Professional ,
Sep 16, 2020

Copy link to clipboard

Copied

What calculation does you use?

Likes

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
Reply
Loading...
Sep 16, 2020 0
Most Valuable Participant ,
Sep 16, 2020

Copy link to clipboard

Copied

That's because the ".00" is added by the Number Format script. It's not an actual part of the field's value.

You should first check if the value contains a ".". If so, split by it and proceed like before. If not, treat the whole value as you do the mins in Text2.

Likes

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
Reply
Loading...
Sep 16, 2020 0
Contributor ,
Sep 16, 2020

Copy link to clipboard

Copied

there is no formatting done in Text1 .   06.00 is entered manually   Format tab is set to none

Likes

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
Reply
Loading...
Sep 16, 2020 0
Adobe Community Professional ,
Sep 16, 2020

Copy link to clipboard

Copied

Does you enter the value or does you use a calculation?

Likes

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
Reply
Loading...
Sep 16, 2020 0
Contributor ,
Sep 16, 2020

Copy link to clipboard

Copied

will be using both.. according to requirement.

 

Also plz see this post of mine :

https://community.adobe.com/t5/acrobat/adobe-acrobat-forms-add-a-specific-number-at-specific-interva...

Likes

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
Reply
Loading...
Sep 16, 2020 0
Adobe Community Professional ,
Sep 16, 2020

Copy link to clipboard

Copied

At Text 3 add  a message output:

 

var mins = this.getField("Text1").valueAsString;
console.show();
console.println(mins);
event.value = mins.split(".")[1];

Likes

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
Reply
Loading...
Sep 16, 2020 0
Contributor ,
Sep 16, 2020

Copy link to clipboard

Copied

Doesnot work 

console shows following error

InvalidSetError: Set not possible, invalid or unknown.
Event.value:4:Field Text3:Calculate
2

Likes

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
Reply
Loading...
Sep 16, 2020 0
Adobe Community Professional ,
Sep 16, 2020

Copy link to clipboard

Copied

What value have you in Text1?

Likes

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
Reply
Loading...
Sep 16, 2020 0
Contributor ,
Sep 16, 2020

Copy link to clipboard

Copied

Text1 is calculation field     . It' value has formulae   event.value = otherfield/60;

Likes

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
Reply
Loading...
Sep 16, 2020 0
Contributor ,
Sep 16, 2020

Copy link to clipboard

Copied

Likes

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
Reply
Loading...
Sep 16, 2020 0
Adobe Community Professional ,
Sep 16, 2020

Copy link to clipboard

Copied

What can you see in Text1?

Likes

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
Reply
Loading...
Sep 16, 2020 0
Contributor ,
Sep 16, 2020

Copy link to clipboard

Copied

the result of the formulae  for ex   4800/60 = 80.00;   or 90/60 = 1.50 

Likes

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
Reply
Loading...
Sep 16, 2020 0
Adobe Community Professional ,
Sep 16, 2020

Copy link to clipboard

Copied

You see 80.00 or 1.50 in the field?

Post a screenshot.

Likes

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
Reply
Loading...
Sep 16, 2020 0
Adobe Community Professional ,
Sep 16, 2020

Copy link to clipboard

Copied

You will get the error message when there is no point or no character after the point.

Likes

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
Reply
Loading...
Sep 16, 2020 0
Engaged ,
Sep 16, 2020

Copy link to clipboard

Copied

Just make sure field calculation order is like this:

Izrezak.PNG

and it should work fine.

 

Likes

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
Reply
Loading...
Sep 16, 2020 0
Engaged ,
Sep 17, 2020

Copy link to clipboard

Copied

Sorry about my first post I thought you are just having troubles to make it work.

Anyway, you can try this workaround:

If result is whole number field "text3" will show 00 else it will split decimals normaly.

var mins = Number(this.getField("Text1").value);
var split = mins.toString().split(".")[1];
var int = Number.isInteger(mins);
if(int == true){
event.value = "00";}
else if(int == false){
event.value = split;}

It works for calculations so you don't need to enter value manually.

Hope that can help you 🙂

Likes

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
Reply
Loading...
Sep 17, 2020 0
Most Valuable Participant ,
Sep 17, 2020

Copy link to clipboard

Copied

I would recommend against using this kind of construction:

var split = mins.toString().split(".")[1];

You're making an assumption there that there is a period in the string. If there isn't, your script will error out.

It's better to do it like this:

 

var minsParts = mins.toString().split(".");
if (minsParts.length==2) {
// there's one period in the string, handle as usual
} else {
// there's more than one period in the string, or none at all, handle as needed
}

Likes

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
Reply
Loading...
Sep 17, 2020 0
Contributor ,
Sep 17, 2020

Copy link to clipboard

Copied

ok.. thanks NesaNurani and try67   ...

script is working now... as required .. below is the script i used:

 

var mins = Number(this.getField("Text1").value);

var minsParts = mins.toString().split(".");

if (minsParts.length==2) {
minsParts[1];}
else {event.value =event.value = "00"  ;}

Likes

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
Reply
Loading...
Sep 17, 2020 0