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 1 commit
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
7 changes: 6 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,11 @@ 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 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 || ''}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we exclude the query string parm completely if props.language is undefined? Not sure if there is any adverse side-effects with sending an empty value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that I tested and it was working when the value is an empty string, but for me it makes sense just to remove it


this._tracker.setFormData(
form.formItemId.value,
Expand Down