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

Added option for AnimationFieldFormat to configure “invalidCharacters… #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions AnimatedField/Classes/AnimatedField+TextFieldDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ extension AnimatedField: UITextFieldDelegate {

// Copy new character
var newInput = string

// Replace special characters in newInput
newInput = newInput.replacingOccurrences(of: "`", with: "")
newInput = newInput.replacingOccurrences(of: "^", with: "")
newInput = newInput.replacingOccurrences(of: "¨", with: "")

// Replace special characters in textField
textField.text = textField.text?.replacingOccurrences(of: "`", with: "")
textField.text = textField.text?.replacingOccurrences(of: "^", with: "")
textField.text = textField.text?.replacingOccurrences(of: "¨", with: "")


let invalidCharacters = format.invalidCharacters.map { String($0) }
for invalidCharacter in invalidCharacters {
// Replace special characters in newInput
newInput = newInput.replacingOccurrences(of: invalidCharacter, with: "")

// Replace special characters in textField
textField.text = textField.text?.replacingOccurrences(of: invalidCharacter, with: "")
}

// Apply uppercased & lowercased if available
if uppercased { newInput = newInput.uppercased() }
if lowercased { newInput = newInput.lowercased() }
Expand Down
21 changes: 10 additions & 11 deletions AnimatedField/Classes/AnimatedField+TextViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@ extension AnimatedField: UITextViewDelegate {

// Copy new character
var newInput = text

// Replace special characters in newInput
newInput = newInput.replacingOccurrences(of: "`", with: "")
newInput = newInput.replacingOccurrences(of: "^", with: "")
newInput = newInput.replacingOccurrences(of: "¨", with: "")

// Replace special characters in textView
textView.text = textView.text?.replacingOccurrences(of: "`", with: "")
textView.text = textView.text?.replacingOccurrences(of: "^", with: "")
textView.text = textView.text?.replacingOccurrences(of: "¨", with: "")


let invalidCharacters = format.invalidCharacters.map { String($0) }
for invalidCharacter in invalidCharacters {
// Replace special characters in newInput
newInput = newInput.replacingOccurrences(of: invalidCharacter, with: "")

// Replace special characters in textView
textView.text = textView.text?.replacingOccurrences(of: invalidCharacter, with: "")
}

// Apply uppercased & lowercased if available
if uppercased { newInput = newInput.uppercased() }
if lowercased { newInput = newInput.lowercased() }
Expand Down
7 changes: 5 additions & 2 deletions AnimatedField/Classes/AnimatedFieldFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import Foundation

public struct AnimatedFieldFormat {


/// String of characters to block/filter from input
public var invalidCharacters = "`^¨"

/// Title always visible
public var titleAlwaysVisible = false

/// Font for title label
public var titleFont = UIFont.systemFont(ofSize: 13, weight: .regular)

Expand Down