@@ -23,6 +23,7 @@ export function extractDocumentFields(result) {
2323 const parseResultInfo = { } ;
2424 if ( ! result . exception ) {
2525 const type = result . getFieldValue ( "documentCode" ) ;
26+ const documentNumber = type === "P" ? "passportNumber" : "documentNumber" ;
2627 const documentType = JSON . parse ( result . jsonString ) . CodeType ;
2728 const birthYear = result . getFieldValue ( "birthYear" ) ;
2829 const birthYearBase = parseInt ( birthYear ) > new Date ( ) . getFullYear ( ) % 100 ? "19" : "20" ;
@@ -33,13 +34,30 @@ export function extractDocumentFields(result) {
3334 const fullExpiryYear = `${ expiryYearBase } ${ expiryYear } ` ;
3435
3536 parseResultInfo [ "Document Type" ] = documentType ;
36- parseResultInfo [ "Surname" ] = result . getFieldValue ( "primaryIdentifier" ) ;
37- parseResultInfo [ "Given Name" ] = result . getFieldValue ( "secondaryIdentifier" ) ;
38- parseResultInfo [ "Nationality" ] = result . getFieldValue ( "nationality" ) ;
39- parseResultInfo [ "Document Number" ] =
40- type === "P" ? result . getFieldValue ( "passportNumber" ) : result . getFieldValue ( "documentNumber" ) ;
41- parseResultInfo [ "Issuing State" ] = result . getFieldValue ( "issuingState" ) ;
42- parseResultInfo [ "Sex" ] = result . getFieldValue ( "sex" ) ;
37+ parseResultInfo [ "Surname" ] = {
38+ text : result . getFieldValue ( "primaryIdentifier" ) ,
39+ status : result . getFieldValidationStatus ( "primaryIdentifier" ) ,
40+ } ;
41+ parseResultInfo [ "Given Name" ] = {
42+ text : result . getFieldValue ( "secondaryIdentifier" ) ,
43+ status : result . getFieldValidationStatus ( "secondaryIdentifier" ) ,
44+ } ;
45+ parseResultInfo [ "Nationality" ] = {
46+ text : result . getFieldValue ( "nationality" ) ,
47+ status : result . getFieldValidationStatus ( "nationality" ) ,
48+ } ;
49+ parseResultInfo [ "Document Number" ] = {
50+ text : result . getFieldValue ( documentNumber ) ,
51+ status : result . getFieldValidationStatus ( documentNumber ) ,
52+ } ;
53+ parseResultInfo [ "Issuing State" ] = {
54+ text : result . getFieldValue ( "issuingState" ) ,
55+ status : result . getFieldValidationStatus ( "issuingState" ) ,
56+ } ;
57+ parseResultInfo [ "Sex" ] = {
58+ text : result . getFieldValue ( "sex" ) ,
59+ status : result . getFieldValidationStatus ( "sex" ) ,
60+ } ;
4361 parseResultInfo [ "Date of Birth (YYYY-MM-DD)" ] =
4462 fullBirthYear + "-" + result . getFieldValue ( "birthMonth" ) + "-" + result . getFieldValue ( "birthDay" ) ;
4563 parseResultInfo [ "Date of Expiry (YYYY-MM-DD)" ] =
@@ -125,9 +143,41 @@ export function resultToHTMLElement(field, value) {
125143 spanFieldName . className = "field-name" ;
126144 const spanValue = document . createElement ( "span" ) ;
127145 spanValue . className = "field-value" ;
146+ const statusIcon = document . createElement ( "span" ) ;
147+ statusIcon . className = "status-icon" ;
148+
149+ // Define success and failed icons
150+ const icons = {
151+ success : `<svg class="w-4 h-4" viewBox="0 0 20 20" fill="currentColor">
152+ <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd"/>
153+ </svg>` ,
154+ failed : `<svg class="w-4 h-4" viewBox="0 0 20 20" fill="currentColor">
155+ <path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"/>
156+ </svg>` ,
157+ } ;
158+
159+ // Handle validation status based on EnumValidationStatus
160+ switch ( value ?. status ) {
161+ case Dynamsoft . DCP . EnumValidationStatus . VS_SUCCEEDED :
162+ statusIcon . innerHTML = icons . success ;
163+ statusIcon . className += " status-success" ;
164+ statusIcon . title = "Validation passed" ;
165+ break ;
166+ case Dynamsoft . DCP . EnumValidationStatus . VS_FAILED :
167+ statusIcon . innerHTML = icons . failed ;
168+ statusIcon . className += " status-failed" ;
169+ statusIcon . title = "Validation failed" ;
170+ break ;
171+ case Dynamsoft . DCP . EnumValidationStatus . VS_NONE :
172+ default :
173+ // Don't add any icon for VS_NONE
174+ statusIcon . style . display = "none" ;
175+ break ;
176+ }
128177
129- spanFieldName . innerText = `${ field } : ` ;
130- spanValue . innerText = `${ value || "Not detected" } ` ;
178+ spanFieldName . innerText = `${ field } ` ;
179+ spanFieldName . append ( statusIcon ) ;
180+ spanValue . innerText = `${ value ?. text || value || "Not detected" } ` ;
131181
132182 p . appendChild ( spanFieldName ) ;
133183 p . appendChild ( spanValue ) ;
0 commit comments