Skip to content

Commit

Permalink
fix: fix removal of * in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerre committed Feb 11, 2023
1 parent 6e7f059 commit 248dd8b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/tests/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,11 @@ describe('Validator', () => {
const label = input.nextSibling as HTMLLabelElement;

expect(label).toBeDefined();
console.log(label.textContent);
expect(label.textContent).toBe(
errors[0].error.replace(/<\/?em>/g, '')
);

expect(label.textContent?.endsWith('*')).toBeFalsy();
}

Expand Down
6 changes: 3 additions & 3 deletions src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,11 @@ export function getInputLabel(input: FormInput): string {

const placeholderText = input.getAttribute('placeholder');

if (label?.innerText?.length) {
labelText = label.innerText.trim();
if (label?.textContent?.length) {
labelText = label.textContent.trim();

if (labelText.length > 1 && labelText.endsWith('*')) {
labelText.slice(0, -1);
labelText = labelText.replace(/\s?\*$/, '');
}
} else if (placeholderText?.length) {
labelText = placeholderText;
Expand Down

0 comments on commit 248dd8b

Please sign in to comment.