Skip to content

Commit

Permalink
Merge pull request #59 from oneblink/ON-34235
Browse files Browse the repository at this point in the history
ON-34235 # added `formElementsService.fixElementName()`
  • Loading branch information
kizaonline authored Aug 23, 2023
2 parents 84e93d1 + 0afcde6 commit a6d6829
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- `formElementsService.fixElementName()`

## [4.0.0] - 2023-07-26

### Added
Expand Down
16 changes: 16 additions & 0 deletions src/formElementsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,21 @@ function determineIsInfoPage(form: FormTypes.Form): boolean {
return !foundInputElement
}

/**
* Remove invalid characters from a form element name.
*
* @param elementName
* @returns
*/
const fixElementName = (elementName: string) => {
// removes characters that aren't letters, numbers, underscores or dashes
// replaces empty spaces with _
return elementName
.replace(/[^-\w\s]/g, '')
.replace(/\s/g, '_')
.trim()
}

export {
forEachFormElement,
forEachFormElementWithOptions,
Expand All @@ -308,4 +323,5 @@ export {
ElementWYSIWYGRegex,
matchElementsTagRegex,
determineIsInfoPage,
fixElementName
}

0 comments on commit a6d6829

Please sign in to comment.