@@ -7,20 +7,7 @@ import type { UmbContextProviderController } from '@umbraco-cms/backoffice/conte
7
7
import { type UmbClassInterface , UmbControllerBase } from '@umbraco-cms/backoffice/class-api' ;
8
8
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api' ;
9
9
import { UmbObjectState } from '@umbraco-cms/backoffice/observable-api' ;
10
-
11
- /**
12
- * Helper method to replace the start of a string with another string.
13
- * @param path {string}
14
- * @param startFrom {string}
15
- * @param startTo {string}
16
- * @returns {string }
17
- */
18
- function ReplaceStartOfString ( path : string , startFrom : string , startTo : string ) : string {
19
- if ( path . startsWith ( startFrom + '.' ) ) {
20
- return startTo + path . slice ( startFrom . length ) ;
21
- }
22
- return path ;
23
- }
10
+ import { ReplaceStartOfPath } from '../utils/replace-start-of-path.function.js' ;
24
11
25
12
/**
26
13
* Validation Context is the core of Validation.
@@ -143,7 +130,7 @@ export class UmbValidationController extends UmbControllerBase implements UmbVal
143
130
}
144
131
this . #parentMessages = msgs ;
145
132
msgs . forEach ( ( msg ) => {
146
- const path = ReplaceStartOfString ( msg . path , this . #baseDataPath! , '$' ) ;
133
+ const path = ReplaceStartOfPath ( msg . path , this . #baseDataPath! , '$' ) ;
147
134
// Notice, the local message uses the same key. [NL]
148
135
this . messages . addMessage ( msg . type , path , msg . body , msg . key ) ;
149
136
} ) ;
@@ -164,7 +151,7 @@ export class UmbValidationController extends UmbControllerBase implements UmbVal
164
151
this . #localMessages = msgs ;
165
152
msgs . forEach ( ( msg ) => {
166
153
// replace this.#baseDataPath (if it starts with it) with $ in the path, so it becomes relative to the parent context
167
- const path = ReplaceStartOfString ( msg . path , '$' , this . #baseDataPath! ) ;
154
+ const path = ReplaceStartOfPath ( msg . path , '$' , this . #baseDataPath! ) ;
168
155
// Notice, the parent message uses the same key. [NL]
169
156
this . #parent! . messages . addMessage ( msg . type , path , msg . body , msg . key ) ;
170
157
} ) ;
0 commit comments