@@ -18,11 +18,16 @@ const isFormSchemaStateValid = ({
1818 validation,
1919 buttonDisabled,
2020 stateMachineService,
21+ formSchemaXHR = { } ,
22+ isStepper,
2123} ) => {
2224 if ( get ( uiSchema , 'ui:page.props.ui:schemaErrors' )
2325 || ! has ( uiSchema , 'ui:page.props.ui:schemaErrors' ) ) {
2426 try {
25- const transformedSchema = transformSchema ( schema ) ;
27+ const transformedSchema = transformSchema ( {
28+ ...schema ,
29+ ...formSchemaXHR ,
30+ } ) ;
2631 const ajv = new Ajv ( ) ;
2732 const validate = ajv . compile ( transformedSchema ) ;
2833 // eslint-disable-next-line @typescript-eslint/no-floating-promises
@@ -36,10 +41,12 @@ const isFormSchemaStateValid = ({
3641
3742 const externalValidations = isFormInValid ( validation ) ;
3843 if ( externalValidations && ! buttonDisabled ) {
39- stateMachineService . send ( FORM_STATE_CONFIG . FORM_STATE_ERROR_EVENTS . ERROR , {
40- hasError : externalValidations ,
41- validation,
42- } ) ;
44+ if ( stateMachineService && typeof stateMachineService . send === 'function' ) {
45+ stateMachineService . send ( FORM_STATE_CONFIG . FORM_STATE_ERROR_EVENTS . ERROR , {
46+ hasError : externalValidations ,
47+ validation,
48+ } ) ;
49+ }
4350 return {
4451 schemaErrors : externalValidations ,
4552 transformedSchema,
@@ -48,10 +55,12 @@ const isFormSchemaStateValid = ({
4855
4956 if ( ! externalValidations && validate . errors && ! buttonDisabled ) {
5057 validate . errors . forEach ( ( err ) => {
51- stateMachineService . send ( FORM_STATE_CONFIG . FORM_STATE_ERROR_EVENTS . ERROR , {
52- hasError : err ,
53- validation,
54- } ) ;
58+ if ( stateMachineService && typeof stateMachineService . send === 'function' ) {
59+ stateMachineService . send ( FORM_STATE_CONFIG . FORM_STATE_ERROR_EVENTS . ERROR , {
60+ hasError : err ,
61+ validation,
62+ } ) ;
63+ }
5564 } ) ;
5665 return {
5766 schemaErrors : validate . errors ,
@@ -65,7 +74,20 @@ const isFormSchemaStateValid = ({
6574 } ;
6675 }
6776 catch ( err ) {
68- // console.log('err', err);
77+ if ( ! isStepper ) {
78+ const transformedSchema = transformSchema ( {
79+ ...schema ,
80+ ...formSchemaXHR ,
81+ } ) ;
82+ return {
83+ schemaErrors : [ {
84+ "rule" : "schemaError" ,
85+ "title" : "Invalid Form Schema" ,
86+ "message" : String ( err )
87+ } ] ,
88+ transformedSchema,
89+ } ;
90+ }
6991 }
7092 }
7193
0 commit comments