@@ -6,6 +6,7 @@ import {EnumerationField, EnumerationFieldValidation, EnumerationFieldValue} fro
6
6
import { WrappedBoolean } from '../../data-field-template/models/wrapped-boolean' ;
7
7
import { TranslateService } from '@ngx-translate/core' ;
8
8
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete' ;
9
+ import { EnumerationAutocompleteFilterProperty } from './enumeration-autocomplete-filter-property' ;
9
10
10
11
@Component ( {
11
12
selector : 'ncc-abstract-enumeration-autocomplete-field' ,
@@ -44,18 +45,6 @@ export abstract class AbstractEnumerationAutocompleteSelectFieldComponent implem
44
45
this . filteredOptions = undefined ;
45
46
}
46
47
47
- /**
48
- * Function to filter out matchless options without accent and case-sensitive differences
49
- * @param value to compare matching options
50
- * @return return matched options
51
- */
52
- private _filter ( value : string ) : Array < EnumerationFieldValue > {
53
- const filterValue = value ?. toLowerCase ( ) . normalize ( 'NFD' ) . replace ( / [ \u0300 - \u036f ] / g, '' ) ;
54
-
55
- return this . enumerationField . choices . filter ( option => option . value . toLowerCase ( ) . normalize ( 'NFD' )
56
- . replace ( / [ \u0300 - \u036f ] / g, '' ) . indexOf ( filterValue ) === 0 ) ;
57
- }
58
-
59
48
change ( ) {
60
49
if ( this . text . value !== undefined ) {
61
50
this . filteredOptions = of ( this . _filter ( this . text . value ) ) ;
@@ -71,6 +60,50 @@ export abstract class AbstractEnumerationAutocompleteSelectFieldComponent implem
71
60
return ! this . formControlRef . disabled && ! this . formControlRef . valid && this . text . control . touched ;
72
61
}
73
62
63
+ protected checkPropertyInComponent ( property : string ) : boolean {
64
+ return ! ! this . enumerationField . component && ! ! this . enumerationField . component . properties && property in this . enumerationField . component . properties ;
65
+ }
66
+
67
+ protected filterType ( ) : string | undefined {
68
+ if ( this . checkPropertyInComponent ( 'filter' ) ) {
69
+ return this . enumerationField . component . properties . filter ;
70
+ }
71
+ }
72
+
73
+ protected _filter ( value : string ) : Array < EnumerationFieldValue > {
74
+ let filterType = this . filterType ( ) ?. toLowerCase ( )
75
+ switch ( filterType ) {
76
+ case EnumerationAutocompleteFilterProperty . SUBSTRING :
77
+ return this . _filterInclude ( value ) ;
78
+ case EnumerationAutocompleteFilterProperty . PREFIX :
79
+ return this . _filterIndexOf ( value ) ;
80
+ default :
81
+ return this . _filterIndexOf ( value ) ;
82
+ }
83
+ }
84
+
85
+ protected _filterInclude ( value : string ) : Array < EnumerationFieldValue > {
86
+ const filterValue = value ?. toLowerCase ( ) . normalize ( 'NFD' ) . replace ( / [ \u0300 - \u036f ] / g, '' ) ;
87
+ return this . enumerationField . choices . filter ( option =>
88
+ option . value . toLowerCase ( )
89
+ . normalize ( 'NFD' )
90
+ . replace ( / [ \u0300 - \u036f ] / g, '' )
91
+ . includes ( filterValue ) ) ;
92
+ }
93
+
94
+
95
+ /**
96
+ * Function to filter out matchless options without accent and case-sensitive differences
97
+ * @param value to compare matching options
98
+ * @return return matched options
99
+ */
100
+ protected _filterIndexOf ( value : string ) : Array < EnumerationFieldValue > {
101
+ const filterValue = value ?. toLowerCase ( ) . normalize ( 'NFD' ) . replace ( / [ \u0300 - \u036f ] / g, '' ) ;
102
+
103
+ return this . enumerationField . choices . filter ( option => option . value . toLowerCase ( ) . normalize ( 'NFD' )
104
+ . replace ( / [ \u0300 - \u036f ] / g, '' ) . indexOf ( filterValue ) === 0 ) ;
105
+ }
106
+
74
107
public renderSelection = ( key ) => {
75
108
if ( key !== undefined && key !== '' && key !== null ) {
76
109
if ( this . enumerationField . choices . find ( choice => choice . key === key ) ) {
0 commit comments