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

feat: add nonOptionalErrorMsg props #757

Merged
merged 9 commits into from
Nov 11, 2023
Merged
9 changes: 6 additions & 3 deletions lib/build/emailpassword-shared4.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions lib/build/emailpassword-shared7.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions lib/ts/recipe/emailpassword/components/library/formBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,7 @@ export const FormBase: React.FC<FormBaseProps<any>> = (props) => {
if (errorMessage === "Field is not optional") {
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
const fieldConfigData = props.formFields.find((f) => f.id === fs.id);
// replace non-optional server error message from nonOptionalErrorMsg
if (
fieldConfigData?.nonOptionalErrorMsg !== undefined &&
fieldConfigData?.nonOptionalErrorMsg !== ""
) {
if (fieldConfigData?.nonOptionalErrorMsg !== undefined) {
return fieldConfigData?.nonOptionalErrorMsg;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/ts/recipe/emailpassword/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@ export function mergeFormFields(
// If new field, push to mergeFormFields.
if (isNewField) {
mergedFormFields.push({
optional: false,
placeholder: userField.label,
validate: defaultValidate,
...userField,
optional: Boolean(userField.optional),
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
});
}
}
Expand All @@ -340,7 +340,7 @@ export function mergeFormFields(
export function getFormattedFormField(field: NormalisedFormField): NormalisedFormField {
// Fields with the 'nonOptionalErrorMsg' property must have a valid message defined
if (field.optional === false && field.nonOptionalErrorMsg === "") {
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(`nonOptionalErrorMsg for field ${field.id} cannot be empty`);
throw new Error(`nonOptionalErrorMsg for field ${field.id} cannot be an empty string`);
}
return {
...field,
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/signup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ describe("SuperTokens SignUp", function () {
});

it("Check if empty string for nonOptionalErrorMsg throws error", async function () {
const expectedErrorMessage = "nonOptionalErrorMsg for field city cannot be empty";
const expectedErrorMessage = "nonOptionalErrorMsg for field city cannot be an empty string";
let pageErrorMessage = "";
page.on("pageerror", (err) => {
pageErrorMessage = err.message;
Expand Down
Loading