Ayush Saraf
Ayush Saraf

Reputation: 1

In Angular 12 : ng2-pdfjs-viewer not read all the values of fillable pdf some text inputs in html collection it returns null while reading from iframe

In Angular 12 : when try to read the fillable changed values using ng2-pdfjs-viewer using iframe for some of the text fields it gave the null value instead of that text field, html collection of that input field also null but it present in the child nodes method using getElementById

this.mappings.map((input: any) => { let iFrameElement = document.getElementsByTagName('iframe');

 const ele = <HTMLInputElement>(
     iFrameElement[0].contentWindow?.document.getElementById(input.id)
  );

 

console.log(input.id, ele);// here input has id but and it present in html still ele gives null

  if (input.type === PdfFieldType.CHECKBOX) {
    if (ele == null) {
      this.isSaveInProgress = false;
      this.snackbarService.errorSnackBar(
        'Something went wrong while trying to save PDF. Please contact Madaket admin.'
      );
      return;
    }
    if (ele.checked) {
      this.changedData.set(input.name, 'On');
    } else {
      this.changedData.set(input.name, 'Off');
    }
  } else if (input.type === PdfFieldType.RADIOBUTTON) {
    if (ele == null) {
      this.isSaveInProgress = false;
      this.snackbarService.errorSnackBar(
        'Something went wrong while trying to save PDF. Please contact Madaket admin.'
      );
      return;
    }
    if (ele.defaultChecked != ele.checked) {
      if (input.buttonValue.includes('Yes')) {
        if (ele.checked) {
          this.changedData.set(input.name, 'Yes');
        } else {
          this.changedData.set(input.name, 'No');
        }
      } else if (input.buttonValue.includes('No')) {
        if (ele.checked) {
          this.changedData.set(input.name, 'No');
        } else {
          this.changedData.set(input.name, 'Yes');
        }
      }
    }
    {
      if (!this.checkIfRadioChangeIsAlreadyCaptured(input)) {
        this.changedData.set(input.name, 'Off');
      }
    }
  } else if (input.type !== PdfFieldType.PUSHBUTTON && ele != null) {
    if (ele) {
      this.changedData.set(input.name, ele.value);
    } else {
    }
  }
});

Upvotes: 0

Views: 45

Answers (0)

Related Questions