Skip to content

Commit

Permalink
fixes #932 - move transformTag callback to be called before valitat…
Browse files Browse the repository at this point in the history
…ion happens
  • Loading branch information
Yair Even Or authored and Yair Even Or committed Oct 25, 2021
1 parent 24eee59 commit b196a71
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ editTags.*clicks* | <sub>Number</sub> | 2
editTags.*keepInvalid* | <sub>Boolean</sub> | true | keeps invalid edits as-is until `esc` is pressed while in focus
templates | <sub>Object</sub> | <sub>`wrapper`, `tag`, `dropdownItem`</sub> | Object consisting of functions which return template strings
validate | <sub>Function</sub> | | If the `pattern` setting does not meet your needs, use this function, which recieves *tag data object* as an argument and should return `true` if validaiton passed or `false`/`string` of not. A *string* may be returned as the reason of the validation failure.
transformTag | <sub>Function</sub> | | Takes a tag data as argument and allows mutating it before a tag is created or edited.<br>Should not `return` anything, only **mutate**.
transformTag | <sub>Function</sub> | | Takes a tag data as argument and allows mutating it before a tag is created or edited and also before validation.<br>Should not `return` anything, only **mutate** the argument.
keepInvalidTags | <sub>Boolean</sub> | false | If `true`, do not remove tags which did not pass validation
skipInvalid | <sub>Boolean</sub> | false | If `true`, do not add invalid, temporary, tags before automatically removing them
backspace | <sub>*</sub> | true | On pressing backspace key:<br> `true` - remove last tag <br>`edit` - edit last tag<br>`false` - do nothing (useful for outside style)
Expand Down
6 changes: 3 additions & 3 deletions src/tagify.js
Original file line number Diff line number Diff line change
Expand Up @@ -1040,11 +1040,12 @@ Tagify.prototype = {
tagData = this.normalizeTags(preInterpolated)[0] || {value:preInterpolated}
}

transformTag.call(this, tagData)

if( !maxTagsReached &&
s2.length > 1 &&
(!enforceWhitelist || this.isTagWhitelisted(tagData.value)) &&
!(!duplicates && this.isTagDuplicate(tagData.value)) ){
transformTag.call(this, tagData)

// in case "tagTextProp" setting is set to other than "value" and this tag does not have this prop
textProp = tagData[tagTextProp] ? tagTextProp : 'value'
Expand Down Expand Up @@ -1199,9 +1200,8 @@ Tagify.prototype = {

// shallow-clone tagData so later modifications will not apply to the source
tagData = Object.assign({}, originalData)
tagData.__isValid = this.hasMaxTags() || this.validateTag(tagData)

_s.transformTag.call(this, tagData)
tagData.__isValid = this.hasMaxTags() || this.validateTag(tagData)

if( tagData.__isValid !== true ){
if( skipInvalid )
Expand Down

0 comments on commit b196a71

Please sign in to comment.