class MyAnnotationModifiedListener: ToolManager.AnnotationModificationListener{
override fun onAnnotationsModified(annots: MutableMap<Annot, Int>?, extra: Bundle?) {
annots?.forEach { mapEntry ->
val annotation = mapEntry.key
if(annotation != null && annotation.isValid){
if(annotation.type == Annot.e_Widget) {
val widget = Widget(annotation)
val field = widget.field
//todo check filled state
}
}
}
}
}
val annotationModifiedListener = MyAnnotationModifiedListener()
val toolManger = mPdfViewCtrlTabHostFragment.currentPdfViewCtrlFragment.toolManager
toolManger.addAnnotationModificationListener(annotationModifiedListener)
thanks for the reply. This is useful to get the callback for the edited form field.
Also, suggest how to identify if all the mandatory form fields are filled or not by the user?
We need to enable submit button only on filling the mandatory fields.
Could you tell us what kind of form fields you would like to check? How are you determining which form fields are mandatory (I assume the mandatory fields will have a predetermined name)?
For example, you can call the following to check whether text fields are filled out:
private fun checkFields(pdfViewCtrlTabHostFragment: PdfViewCtrlTabHostFragment2) {
val pdfViewCtrl: PDFViewCtrl = pdfViewCtrlTabHostFragment.currentPdfViewCtrlFragment.pdfViewCtrl
val doc = pdfViewCtrl.doc
var shouldUnlock = false
try {
doc.lockRead()
shouldUnlock = true
val fieldIterator = doc.fieldIterator
while (fieldIterator.hasNext()) {
val field = fieldIterator.next()
if (field != null) {
// Assuming the mandatory field has a predetermined name, you can check the field name
if (field.name != null && field.name == "mandatoryFieldName") {
val type = field.type
when (type) {
Field.e_text -> {
val value = field.valueAsString
if (!Utils.isNullOrEmpty(value)) {
// Text field is filled
// ...
}
}
// Handle other field types...
}
}
}
}
} catch (e: PDFNetException) {
if (shouldUnlock) {
Utils.unlockReadQuietly(doc)
}
}
}