moved by request
This commit is contained in:
parent
84adccd187
commit
5faa20cf9b
@ -97,23 +97,7 @@ import UIKit
|
||||
get { textField.text }
|
||||
set {
|
||||
textEntryFieldModel?.text = newValue
|
||||
|
||||
guard let regex = textEntryFieldModel?.displayFormat,
|
||||
let mask = textEntryFieldModel?.displayMask,
|
||||
let newText = newValue
|
||||
else {
|
||||
textField.text = newValue
|
||||
return
|
||||
}
|
||||
|
||||
let range = NSRange(newText.startIndex..., in: newText)
|
||||
|
||||
if let regex = try? NSRegularExpression(pattern: regex) {
|
||||
let maskedText = regex.stringByReplacingMatches(in: newText,
|
||||
range: range,
|
||||
withTemplate: mask)
|
||||
textField.text = maskedText
|
||||
}
|
||||
textField.text = newValue
|
||||
}
|
||||
}
|
||||
|
||||
@ -279,9 +263,28 @@ import UIKit
|
||||
self.isValid = isValid
|
||||
}
|
||||
|
||||
regexTextFieldOutputIfAvailable()
|
||||
|
||||
shouldShowError(!isValid)
|
||||
}
|
||||
|
||||
func regexTextFieldOutputIfAvailable() {
|
||||
|
||||
if let regex = textEntryFieldModel?.displayFormat,
|
||||
let mask = textEntryFieldModel?.displayMask,
|
||||
let finalText = text {
|
||||
|
||||
let range = NSRange(finalText.startIndex..., in: finalText)
|
||||
|
||||
if let regex = try? NSRegularExpression(pattern: regex) {
|
||||
let maskedText = regex.stringByReplacingMatches(in: finalText,
|
||||
range: range,
|
||||
withTemplate: mask)
|
||||
textField.text = maskedText
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc public func dismissFieldInput(_ sender: Any?) {
|
||||
resignFirstResponder()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user