Expand my Community achievements bar.

Make a field visible dependent on another fields length - Issue change event

Avatar

Level 2

Hi all,

I want to make a field named "KdAufPos" visible, if another field named "Kontierungselement" (text field) has the character length 7.

I am using the following javascript code in the change event of the Kontierungselement field:

 

console.println("START ");

var currentLength = this.rawValue.length;

var kdAufPos = FormServiceRequestConfirmation.mstPageSet1.mstPage1.frmTitle.KdAufPos;

console.show();

console.println("currentLength "+ currentLength);

 

validateFieldValueLength(currentLength);

function validateFieldValueLength(currentLength){

if (currentLength == 7 ){

console.println("zeichenlänge momentan " + currentLength);

kdAufPos.presence = "visible";

}else{

console.println("KdAufNr ist nicht leer " + currentLength);

}

}

My issue is that the change event is not triggering correctly. After I am opening the PDF and entering data in the field, the console is showing up but don't display my console.println - I got an error with "TypeError: this.rawValue is null".

1861278_pastedImage_12.png

Just after exit the field and click in again, I got the console.println and got displayed sometimes the right and sometimes the wrong length...

What is this error about? Why is it that after clicking out and in again the script seems to work and at least do something?

Any tips?

Thanks a lot!

Regards

Deborah

2 Replies

Avatar

Level 10

Hi Deborah,

You are getting the exception because this.rawValue is null and the null object does not have a length property.

In the change event this.rawValue has not been updated yet.

You probably want to use xfa.event.newText instead.

Regards

Bruce

Avatar

Level 2

Hi Bruce BR001​,

how to use the xfa.event.newText event? Do you have an example?

So in which standard Adobe events (initialize, change, validate...) do I have to put my code in?

Thanks & regards

Deborah