Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nextjs][react]The language of the form is changed after clicking the submit button #1261

Merged
merged 2 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import FileUpload from './field-templates/file-upload';

describe('<Form />', () => {
const p = (): FormProps => ({
language: 'da-DK',
sitecoreApiHost: 'http://jssreactweb',
sitecoreApiKey: '{9B8C268A-171D-4DAA-B131-54B64614BBE0}',
form: {
Expand Down Expand Up @@ -193,7 +194,7 @@ describe('<Form />', () => {
);

expect(c.html()).to.equal(
'<form action="http://jssreactweb/api/jss/formbuilder?fxb.FormItemId=xxx-metadata-item-id&amp;fxb.HtmlPrefix=xxx-html-prefix&amp;sc_apikey={9B8C268A-171D-4DAA-B131-54B64614BBE0}&amp;sc_itemid=xxx-context-item-id" method="POST"><div class="form-errors"></div><span class="fieldWrapper"><h2>Test</h2><button type="submit" class="xxx_css-class" value="xxx_title" name="button-xxx" id="button-xxx">xxx_title</button></span></form>'
'<form action="http://jssreactweb/api/jss/formbuilder?fxb.FormItemId=xxx-metadata-item-id&amp;fxb.HtmlPrefix=xxx-html-prefix&amp;sc_apikey={9B8C268A-171D-4DAA-B131-54B64614BBE0}&amp;sc_itemid=xxx-context-item-id&amp;sc_lang=da-DK" method="POST"><div class="form-errors"></div><span class="fieldWrapper"><h2>Test</h2><button type="submit" class="xxx_css-class" value="xxx_title" name="button-xxx" id="button-xxx">xxx_title</button></span></form>'
);
});
});
Expand Down
5 changes: 4 additions & 1 deletion packages/sitecore-jss-react-forms/src/components/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface ErrorComponentProps {

export interface FormProps {
form: SitecoreForm;
language?: string;
className?: string;
fieldFactory?: FieldFactory;
sitecoreApiHost: string;
Expand Down Expand Up @@ -96,7 +97,9 @@ export class Form extends Component<FormProps, FormState & FieldStateCollection>
return <div>Form data invalid. Forget to set the rendering contents resolver?</div>;
}

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 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,
Expand Down