From f05ecde89b868507a83c6b09146829d851e3696d Mon Sep 17 00:00:00 2001 From: illiakovalenko Date: Fri, 16 Dec 2022 15:02:34 +0200 Subject: [PATCH 1/2] [nextjs][react]The language of the form is changed after clicking the submit button --- .../sitecore-jss-react-forms/src/components/form.test.tsx | 3 ++- packages/sitecore-jss-react-forms/src/components/form.tsx | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/sitecore-jss-react-forms/src/components/form.test.tsx b/packages/sitecore-jss-react-forms/src/components/form.test.tsx index d963d33fff..2938c6a5e3 100644 --- a/packages/sitecore-jss-react-forms/src/components/form.test.tsx +++ b/packages/sitecore-jss-react-forms/src/components/form.test.tsx @@ -11,6 +11,7 @@ import FileUpload from './field-templates/file-upload'; describe('
', () => { const p = (): FormProps => ({ + language: 'da-DK', sitecoreApiHost: 'http://jssreactweb', sitecoreApiKey: '{9B8C268A-171D-4DAA-B131-54B64614BBE0}', form: { @@ -193,7 +194,7 @@ describe('', () => { ); expect(c.html()).to.equal( - '

Test

' + '

Test

' ); }); }); diff --git a/packages/sitecore-jss-react-forms/src/components/form.tsx b/packages/sitecore-jss-react-forms/src/components/form.tsx index 2a18b86dcf..813ecbe550 100644 --- a/packages/sitecore-jss-react-forms/src/components/form.tsx +++ b/packages/sitecore-jss-react-forms/src/components/form.tsx @@ -23,6 +23,7 @@ export interface ErrorComponentProps { export interface FormProps { form: SitecoreForm; + language?: string; className?: string; fieldFactory?: FieldFactory; sitecoreApiHost: string; @@ -96,7 +97,11 @@ export class Form extends Component return
Form data invalid. Forget to set the rendering contents resolver?
; } - const action = `${this.props.sitecoreApiHost}/api/jss/formbuilder?fxb.FormItemId=${form.metadata.itemId}&fxb.HtmlPrefix=${form.htmlPrefix}&sc_apikey=${this.props.sitecoreApiKey}&sc_itemid=${form.contextItemId}`; + const action = `${this.props.sitecoreApiHost}/api/jss/formbuilder?fxb.FormItemId=${ + form.metadata.itemId + }&fxb.HtmlPrefix=${form.htmlPrefix}&sc_apikey=${this.props.sitecoreApiKey}&sc_itemid=${ + form.contextItemId + }&sc_lang=${this.props.language || ''}`; this._tracker.setFormData( form.formItemId.value, From 14acb706a4deb75752d7643e5956b1a16d080c3c Mon Sep 17 00:00:00 2001 From: illiakovalenko Date: Mon, 19 Dec 2022 11:21:59 +0200 Subject: [PATCH 2/2] Make `sc_lang` as optional qs parameter --- packages/sitecore-jss-react-forms/src/components/form.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/sitecore-jss-react-forms/src/components/form.tsx b/packages/sitecore-jss-react-forms/src/components/form.tsx index 813ecbe550..41936c5bac 100644 --- a/packages/sitecore-jss-react-forms/src/components/form.tsx +++ b/packages/sitecore-jss-react-forms/src/components/form.tsx @@ -97,11 +97,9 @@ export class Form extends Component return
Form data invalid. Forget to set the rendering contents resolver?
; } - const action = `${this.props.sitecoreApiHost}/api/jss/formbuilder?fxb.FormItemId=${ - form.metadata.itemId - }&fxb.HtmlPrefix=${form.htmlPrefix}&sc_apikey=${this.props.sitecoreApiKey}&sc_itemid=${ - form.contextItemId - }&sc_lang=${this.props.language || ''}`; + const qsLanguage = this.props.language ? `&sc_lang=${this.props.language}` : ''; + + const action = `${this.props.sitecoreApiHost}/api/jss/formbuilder?fxb.FormItemId=${form.metadata.itemId}&fxb.HtmlPrefix=${form.htmlPrefix}&sc_apikey=${this.props.sitecoreApiKey}&sc_itemid=${form.contextItemId}${qsLanguage}`; this._tracker.setFormData( form.formItemId.value,