Giter VIP home page Giter VIP logo

input-mask-ios's Introduction

Input Mask

Pod Version Badge Awesome Actions Android Telegram license

Input masks restrict data input and allow you to guide users to enter correct values.
Check out our wiki for quick start and further reading.

⚙️ Features

  • Apply formatting to your text fields, see examples
  • Filter out nonessential symbols (e.g. extract 0123456 from +1 (999) 012-34-56)
  • For international phone numbers
    • guess the country from the entered digits
    • apply corresponding value restrictions (e.g. a 🇺🇸US phone will have a format like +1 201 456-7890)
  • Apply number/currency formatting
  • SwiftUI support
  • macOS support
  • Phone numbers: +1 ([000]) [000] [00] [00]
  • Dates: [00]{.}[00]{.}[9900]
  • Serial numbers: [AA]-[00000099]
  • IPv4: [099]{.}[099]{.}[099]{.}[099]
  • Visa/MasterCard numbers: [0000] [0000] [0000] [0000]
  • UK IBAN: GB[00] [____] [0000] [0000] [0000] [00]

Swift Package Manager

dependencies: [
    .Package(url: "https://github.com/RedMadRobot/input-mask-ios", majorVersion: 7)
]

CocoaPods

pod 'InputMask'

Manual

  1. git clone this repository;
  2. Add InputMask.xcodeproj into your project/workspace;
  3. Go to your target's settings, add InputMask.framework under the Embedded Binaries section
  4. For ObjC projects:
    • (~Xcode 8.x) make sure Build Options has Embedded Content Contains Swift Code enabled;
    • import bridging header.

📢 Communication, Questions & Issues

Please take a closer look at our Known issues section before you incorporate our library into your project.

For your bugreports and feature requests please file new issues via GitHub.

Should you have any questions, please search for closed issues or ask questions at StackOverflow with the input-mask tag.

UITextFieldTextDidChange notification and target-action editingChanged event

UITextField with assigned MaskedTextFieldDelegate object won't issue UITextFieldTextDidChange notifications and editingChanged control events. This happens due to the textField(_:shouldChangeCharactersIn:replacementString:) method implementation, which always returns false.

Consider using following workaround in case if you do really need to catch editing events:

class NotifyingMaskedTextFieldDelegate: MaskedTextFieldDelegate {
    weak var editingListener: NotifyingMaskedTextFieldDelegateListener?
    
    override func textField(
        _ textField: UITextField,
        shouldChangeCharactersIn range: NSRange,
        replacementString string: String
    ) -> Bool {
        defer {
            self.editingListener?.onEditingChanged(inTextField: textField)
        }
        return super.textField(textField, shouldChangeCharactersIn: range, replacementString: string)
    }
}


protocol NotifyingMaskedTextFieldDelegateListener: class {
    func onEditingChanged(inTextField: UITextField)
}

Please, avoid at all costs sending SDK events and notifications manually.

Carthage vs. IBDesignables, IBInspectables, views and their outlets

Interface Builder struggles to support modules imported in a form of a dynamic framework. For instance, custom views annotated as IBDesignable, containing IBInspectable and IBOutlet fields aren't recognized properly from the drag'n'dropped *.framework.

In case you are using our library as a Carthage-built dynamic framework, be aware you won't be able to easily wire your MaskedTextFieldDelegate objects and their listeners from storyboards in your project. There is a couple of workarounds described in the corresponding discussion, though.

Also, consider filing a radar to Apple, like this one.

Cut action doesn't put text into the pasteboard

When you cut text, characters get deleted yet you won't be able to paste them somewhere as they aren't actually in your pasteboard.

iOS hardwires UIMenuController's cut action to the UITextFieldDelegate's textField(_:shouldChangeCharactersIn:replacementString:) return value. This means "Cut" behaviour actually depends on the ability to edit the text.

Bad news are, our library returns false in textField(_:shouldChangeCharactersIn:replacementString:), and heavily depends on this false. It would require us to rewrite a lot of logic in order to change this design, and there's no guarantee we'll be able to do so.

Essentially, there's no distinct way to differentiate "Cut selection" and "Delete selection" actions on the UITextFieldDelegate side. However, you may consider using a workaround, which will require you to subclass UITextField overriding its cut(sender:) method like this:

class UITextFieldMonkeyPatch: UITextField {
    override func cut(_ sender: Any?) {
        copy(sender)
        super.cut(sender)
    }
}

From our library perspective, this looks like a highly invasive solution. Thus, in the long term, we are going to investigate a "costly" method to bring the behaviour matching the iOS SDK logic. Yet, here "long term" might mean months.

Incorrect cursor position after pasting

Shortly after new text is being pasted from the clipboard, every UITextInput receives a new value for its selectedTextRange property from the system. This new range is not consistent with the formatted text and calculated caret position most of the time, yet it's being assigned just after set caretPosition call.

To ensure correct caret position is set, it might be assigned asynchronously (presumably after a vanishingly small delay), if caret movement is set to be non-atomic; see MaskedTextFieldDelegate.atomicCursorMovement property.

MaskedTextInputListener

In case you are wondering why do we have two separate UITextFieldDelegate and UITextViewDelegate implementations, the answer is simple: prior to iOS 11 UITextField and UITextView had different behaviour in some key situations, which made it difficult to implement common logic.

Both had the same bug with the UITextInput.beginningOfDocument property, which rendered impossible to use the generic UITextInput protocol UITextField and UITextView have in common.

Since iOS 11 most of the things received their fixes (except for the UITextView edge case). In case your project is not going to support anything below 11, consider using the modern MaskedTextInputListener.

🙏 Special thanks

These folks rock:

The library is distributed under the MIT LICENSE.

input-mask-ios's People

Contributors

diegotl avatar kubilaykiymaci avatar luizzak avatar martintreurnicht avatar taflanidi avatar vani2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

input-mask-ios's Issues

Proper mask not applied after deleting characters

Let have these affineMasks: [0], [00], [000], [0] [000], [0] [000] [000]
Let say I have an input: 1 542 (so [0] [000] mask applied)
When I remove '2' the input is: 1 54 instead of 154

What can I do to fix this?
I'm using the textField to display currency.
I'm using 3.5.0 version

Numeric Mask right to left

Hello, I need to implement a simple decimal mask with the following format:

999.999.999

When I type my text right now, I get the following result:

123.456.78 (left to right)

I need to type my numbers and the mask to work from right to left, so when I type those numbers I get the following result:

12.345.678

Is this possible?

Swift 4. Add full macOS support.

Currently there's quite a limited macOS support with no proper SDK text field listener implementation (see feature/swift4 branch for details).

macOS text fields need special treatment when it comes to implement an «on text change» listener. Consider using a field editor approach described in mail list and corresponding reference docs.

Also, rearrange sources into separate Core, iOS and macOS groups/targets & add matching POD subspecs.

Mail list dump Re: Equivalent of UITextField's textField:shouldChangeCharactersInRange:replacementString for NSTextField Subject: Re: Equivalent of UITextField's textField:shouldChangeCharactersInRange:replacementString for NSTextField From: Aki Inoue Date: Tue, 27 Sep 2011 14:58:42 -0700 Delivered-to: email@hidden Delivered-to: email@hidden Eric,

We really recommend looking at the approach I described earlier using NSFormatter subclass for input validation.

  • (BOOL)isPartialStringValid:(NSString **)partialStringPtr proposedSelectedRange:(NSRangePointer)proposedSelRangePtr originalString:(NSString *)origString originalSelectedRange:(NSRange)origSelRange errorDescription:(NSString **)error;

-textView:shouldChangeTextInRange:replacementString: is used by other AppKit services including undo/redo, input services, & formatter validation, etc.
It's possible for you to interfere with these system services if your override method was not implemented with aware of them. The interface is designed to allow overriding these system services, too.

By using NSFormatter, your method can focus to the validation logic itself since it's invoked after other services.

That said, if you still really need to go that route, you don't need have custom field editor.

All NSControl subclass hosting a field editor is a text view delegate.
You can simply override the delegate method with your custom NSTextField subclass.

For example,

  • (BOOL)textView:(NSTextView *)aTextView shouldChangeTextInRange:(NSRange)aRange replacementString:(NSString *)aString {
    if ([super textView:aTextView shouldChangeTextInRange:aRange replacementString:aString]) {
    id delegate = [self delegate];
    if ([delegate respondsToSelector:@selector(textView:shouldChangeTextInRange:replacementString:)]) return [delegate textView:aTextView shouldChangeTextInRange:aRange replacementString:aString];
    return YES;
    }

    return NO;
    }

should give you essentially what you want.

Aki

On 2011/09/27, at 14:08, Eric Wing wrote:

On 9/21/11, Jens Alfke email@hidden wrote:

On Sep 21, 2011, at 7:42 PM, Eric Wing wrote:

I have been using the delegate callback
textField:shouldChangeCharactersInRange:replacementString for
UITextField.
I am trying to port code over to Mac using NSTextField. Is there
something that provides similar functionality?

Yes, but it’s a bit more complicated due to some rough edges in the AppKit
API that got cleaned up in iOS. The delegate method you’re looking for is in
NSTextView, which is the actual view used to manage editing in a focused
NSTextField. Basically, you should read about “field editors” in the AppKit
docs. You’ll want to give your text field a custom field editor and set
yourself as its delegate.

—Jens

Thanks for the info. That turned out to be a really long side quest.
Had to get into NSCell's and went into areas of NSSecureTextField that
I shouldn't have.

Anyway, I have my field editor mostly working, but I have one follow
up issue. I originally was using:

  • (void) controlTextDidBeginEditing:(NSNotification*)notification
    to get an event callback when the field begins editing.

It seems that once I added my custom field editor, I no longer get
this callback. Strangely, I still get the callback for:

  • (void) controlTextDidEndEditing:(NSNotification*)notification

Is there something I can do to get that first callback back working
again, or is there a substitute? (Currently my workaround is to keep a
bool on my shouldChangeCharactersInRange: to know if I just started
editing, but I would like to know if there is something more elegant.)

Thanks,
Eric

menuController "Cut" not work

I use MaskedTextFieldDelegate and assign it to textFiled (instance of UITextFiled) delegate property. After that, the "Cut" item of menuController not work, text disappear but it not saved in UIPasteboard. Other items like "Copy", "Paste" works correct

Error while using profiler

Hey guys!
I recently tested my app and while try to profile memory leaks I got error in FormatSanitizer.swift in func getFormatBlocks(_ string: String) -> [String] block.
2018-05-11 12 43 17

Error message is Main Thread Checker: UI API called on a background thread: -[UIView retainCount] PID: 1884, TID: 190199, Thread name: (none), Queue name: com.apple.keyboard.xpc, QoS: 25
Please check this :)

P.S. Thanks for awesome library! 👍🏻

Ability to set an empty mask

As I was making my inputs generics so all could take a mask I defaulted the mask to "" (the default in the lib code) and I all inputs stopped accepting chars. Think the empty mask should allow any char or the default should be an allow all mask.

Brazilian Phones

Here in brazil we have a problem that cell phones there are 9 digits and landlines have 8 digits.
We can solve that using affineFormats from PolyMaskTextFieldDelegate but there is a problem, that is not automatically.

self.phonePolyMaskTextFieldDelegate?.affineFormats = [ "([00]) [00000]-[0000]", "([00]) [0000]-[0000]"]

Im using like this. But if i have an 8 digits phone, i do need to type the "-" to force the textfield be 8 digits. Is there any way to do it automatically? Like, if my phone have 8 digits, it stays with the mask ([00]) [0000]-[0000] and if i need to put 9 digits the "-" automatically changes.

Clear button problem

If you clear textfield by clear button, MaskedTextFieldDelegateListener isn't invoked.

TextView support

Hi,

I've been using your lib in my app but I have to convert a textfield to a textview for growing text support. Is there a quick way to make it works with textview or should I port the code.

Mask Brazilian's CPF and CNPJ in the same field

Hi, in Brazil we have there registration numbers named CPF and CNPJ.

The formats are:

  • CPF: [000].[000].[000]-[00]
  • CNPJ: [00].[000].[000]/[0000]-[00]

I wasn't able to figure it out a way of doing this, maybe changing the masked delegate at runtime? How can I do it?

Thanks.

Is any way to get original string ?

Hi, thanks for good library!

I have an issue, let's say, I have a text field with format "{+7} ([000]) [000] [0000]" and property textfield.text gives me "+7 (937) 444 3333", so it's ok for ui, but I need original string for making request to server, is it possible to get original input text "79374443333" ?

XCode 10 and Swift 4.2 fails to build

The pod does not compile with Xcode 10 and Swift 4.2

Installation Type

  • Cocoapods

Additional context

/Users/Damasceno/Documents/GitHub/caronae-ios/Pods/InputMask/Source/InputMask/InputMask/Classes/View/MaskedTextFieldDelegate.swift:167:72: error: 'UITextFieldDidEndEditingReason' has been renamed to 'UITextField.DidEndEditingReason'
    open func textFieldDidEndEditing(_ textField: UITextField, reason: UITextFieldDidEndEditingReason) {
                                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                                       UITextField.DidEndEditingReason
UIKit.UITextFieldDidEndEditingReason:3:18: note: 'UITextFieldDidEndEditingReason' was obsoleted in Swift 4.2
public typealias UITextFieldDidEndEditingReason = UITextField.DidEndEditingReason

Text mask not worked.

Can't create mask with following format:
[A_____________________________________________________]

3.4.1 cannot be use with ObjC

Cannot access MaskedTextFieldDelegate.listener from ObjC because it declares as
open weak var listener: MaskedTextFieldDelegateListener?

Question: Is there any other option to use it without edit the code and add @objc ?

Ability to define a mask with arbitrary number of groups

Prerequisites

done.

Summary

I'd like to define a mask that allows to input an arbitrary number of group of 4 letters separated by space.

Motivation

Easy formatting for IBAN numbers for every country (different lengths)

Describe the solution you'd like

Maybe the ability to use a mask like "[AAAA ]*"

Empty mask

Hey guys!
I use this mask "[…]", but it doesn't allow me to enter different other symbols like this , : ; () " \ -
Can I disable mask or use all symbols, digits, letters, whitespaces?

Fails to copile with Carthage

Cartfile:

git "https://github.com/RedMadRobot/input-mask-ios.git"

Command: carthage update --platform ios

Output:

*** Building scheme "InputMask" in InputMask.xcodeproj
Build Failed
	Task failed with exit code 65:
	/usr/bin/xcrun xcodebuild -project /Users/johnzakharov/Desktop/Xcode/crediton-ios/Carthage/Checkouts/input-mask-ios/Source/InputMask/InputMask.xcodeproj -scheme InputMask -configuration Release -derivedDataPath /Users/johnzakharov/Library/Caches/org.carthage.CarthageKit/DerivedData/input-mask-ios/3.0.0 -sdk iphoneos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean build (launched in /Users/johnzakharov/Desktop/Xcode/crediton-ios/Carthage/Checkouts/input-mask-ios)

This usually indicates that project itself failed to compile. Please check the xcodebuild log for more details: /var/folders/hz/_y3bdbvn025bv6gk1xqq1_jm0000gn/T/carthage-xcodebuild.IgDgmm.log

Log file (inputmask part):

/usr/bin/xcrun xcodebuild -project /Users/johnzakharov/Desktop/Xcode/crediton-ios/Carthage/Checkouts/input-mask-ios/Source/InputMask/InputMask.xcodeproj -scheme InputMask -configuration Release -derivedDataPath /Users/johnzakharov/Library/Caches/org.carthage.CarthageKit/DerivedData/input-mask-ios/3.0.0 -sdk iphoneos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean build (launched in /Users/johnzakharov/Desktop/Xcode/crediton-ios/Carthage/Checkouts/input-mask-ios)User defaults from command line:
    IDEDerivedDataPathOverride = /Users/johnzakharov/Library/Caches/org.carthage.CarthageKit/DerivedData/input-mask-ios/3.0.0

Build settings from command line:
    BITCODE_GENERATION_MODE = bitcode
    CARTHAGE = YES
    CODE_SIGN_IDENTITY = 
    CODE_SIGNING_REQUIRED = NO
    ONLY_ACTIVE_ARCH = NO
    SDKROOT = iphoneos10.3

=== CLEAN TARGET InputMask OF PROJECT InputMask WITH CONFIGURATION Release ===

Check dependencies
“Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.
“Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

** CLEAN FAILED **


The following build commands failed:
	Check dependencies
(1 failure)
=== BUILD TARGET InputMask OF PROJECT InputMask WITH CONFIGURATION Release ===

Check dependencies
“Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.
“Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

** BUILD FAILED **


The following build commands failed:
	Check dependencies
(1 failure)

maskedTextFieldDelegate.put not working on 3.5.0

The title says it all, put(text: into:) doesn't seem to be working on the new version.
I didn't have the time to do extensive testing but was happening on the iPhone SE simulator with iOS 10.
I saw that you changed how that part works because of the UITextView support, so maybe you forgot to call something?

(yes, I did a downgrade and 3.4.1 is working fine)

Get original string

How to get original string?
For example, i have mask {(123)}-[000] and text field text is "(123)456, i want to get what exactly user enter, is that case - 456.

Strong reference

Is there a way for InputMask to work as a weak reference? Because when I pop my viewController it causes memory leak due to the strong reference. But if I set it to weak reference, mask isn't applied

Blank space issues

I'm facing two issues regarding blank space.

  1. I have this mask for credit card: "[0000] [0000] [0000] [0000] [999]" but the main problem is when user finishes typing mandatory numbers, it still says is not completed because the user didn't type the blank space before [999]. How can I fix this issue?

  2. I have this mask for name input: [A…] but it doesn't allow me to input blank space, and it seems there is no symbol for that. I even tried to create my custom notation for blank space but no success. How can I allow at least one letter and optional blank spaces?

Thanks for this awesome library!

Is there a way to disable brackets

As an input I have such mask: +1(999)999 99 99
This is equivalent to InputMask's +1([000])[000] [00] [00]
I setup a custom notation for this mask in the following way:

        let digitNotation = Notation(character: "9", characterSet: .decimalDigits, isOptional: false)
        let upperNotation = Notation(character: "A", characterSet: .uppercaseLetters, isOptional: false)
        let lowerNotation = Notation(character: "a", characterSet: .lowercaseLetters, isOptional: false)
        let alNumNotation = Notation(character: "*", characterSet: .alphanumerics, isOptional: false)
        let notations = [digitNotation, upperNotation, lowerNotation, alNumNotation]
        
        self.maskListener = MaskedTextFieldDelegate(primaryFormat: mask, customNotations: notations)

However since server doesn't send me brackets [], InputMask won't let me type my text properly according to the mask and would instead always output +1(999)999 99 99 as is no matter what I type.

So the question: Is there a way I could tell InputMask engine not to use [] or at least replace brackets with nothing in similar passion as I did for notations?

No outlets

On storyboard, can't set delegate outlet from listener to view controller.
No outlets section in submenu.
2018-04-10 11 02 57

Incorrect cursor position after pasting from clipboard

Mask:

+7 ([000]) [000] [00] [00]

Clipboard contents:

962 123-45-67

Text field contents (vertical line stands for cursor):

+7 (|

After pasting, expected result:

+7 (962) 123 45 67|

Actual result:

+7 (962) 123 45 6|7

Masked text to a Plan text

I am able to do masking but now after successful masking I want to do it reverse mask so that I may send plan text to server. for example if a user enters: (56)-55 (for mask formate ([11])-[11]), I want to make it plan text like 5665 and use it.

Please note that extractedValue is not returning plan text (unmasked text) if it is an issue then, it should be resolved as already referenced here

Ignore autocompletion after deleting character.

For example: Input mask is "+ 7 ([000])-[000]-[00]-[00]".
Entered text: "+7 (999)-"

Now we press delete in keyboard.

Expected result: "+7 (99"
Current result: "+7 (999)"

I think we need to ignore ")-" symbols and delete the last "9" symbol.

Create custom Notation based on existed one.

Hey,

my goal is to create mask that allows text with spaces and dashes. Documentation brings me to custom notation - I can create my own set of characters.

But it's pretty a lot of work there, however, InputMask already has notation that almost fits to my task - I just need add to it two more symbols.

Is it possible?

12.2 Developer beta 2 Crash - initWithCoder error

Prerequisites

  • [X ] Put an X between the brackets on this line if you have done all of the following:
    • read our Wiki;
    • read the entire Known issues section;
    • checked that my issue isn't already filled;
    • searched StackOverflow's input-mask tag for similar problems.

Describe the bug

I noticed that after using ViewController that used a TextField utilising the input mask, the App would crash. This was strange since the that exact page worked the day before and I had not made any changes to that view controller or UI in storyboard - The only change I had made was in my enviroment: I had build the app with xCode 10 Beta 2 to be able to run/test the app on my iphone that is running the beta version of iOS 12.2 Developer beta 2. I decided to build out a new view controller by bringing over all the controlls from the current page one by one and seeing when it breaks - it only broke the moment I add the InputMask Delegate Objects.

Steps to reproduce the behaviour:

Have a page with a InputMask Textfield setup - build app for iOS 12.2 Developer beta 2 (using xCode 10 beta 2)

Expected behaviour
Input Mask functions

Actual behaviour
App crashes: error produced:
Terminating app due to uncaught exception 'NSGenericException', reason: 'This coder requires that replaced objects be returned from initWithCoder:'

That is the core of the problem, however, the rest of the error call stack can be found here:

*** First throw call stack: ( 0 CoreFoundation 0x0000000108ca072b __exceptionPreprocess + 331 1 libobjc.A.dylib 0x000000010768eac5 objc_exception_throw + 48 2 CoreFoundation 0x0000000108ca0585 +[NSException raise:format:] + 197 3 UIFoundation 0x000000010f47e89c UINibDecoderDecodeObjectForValue + 827 4 UIFoundation 0x000000010f47eaf9 UINibDecoderDecodeObjectForValue + 1432 5 UIFoundation 0x000000010f47e554 -[UINibDecoder decodeObjectForKey:] + 251 6 UIKitCore 0x0000000111825e90 -[UIViewController initWithCoder:] + 1021 7 DumaPay Consumer iOS 0x00000001055bde66 $s20DumaPay_Consumer_iOS25TestAddCardViewControllerC5coderACSgSo7NSCoderC_tcfc + 2214 8 DumaPay Consumer iOS 0x00000001055bdf2f $s20DumaPay_Consumer_iOS25TestAddCardViewControllerC5coderACSgSo7NSCoderC_tcfcTo + 47 9 UIKitCore 0x0000000111aaae89 -[UIClassSwapper initWithCoder:] + 246 10 UIFoundation 0x000000010f47e852 UINibDecoderDecodeObjectForValue + 753 11 UIFoundation 0x000000010f47e554 -[UINibDecoder decodeObjectForKey:] + 251 12 UIKitCore 0x0000000111aaf4d1 -[UIRuntimeConnection initWithCoder:] + 178 13 UIFoundation 0x000000010f47e852 UINibDecoderDecodeObjectForValue + 753 14 UIFoundation 0x000000010f47eaf9 UINibDecoderDecodeObjectForValue + 1432 15 UIFoundation 0x000000010f47e554 -[UINibDecoder decodeObjectForKey:] + 251 16 UIKitCore 0x0000000111aacd81 -[UINib instantiateWithOwner:options:] + 1216 17 UIKitCore 0x0000000111fc5290 -[UIStoryboard instantiateViewControllerWithIdentifier:] + 181 18 DumaPay Consumer iOS 0x0000000105623ea9 $s20DumaPay_Consumer_iOS28AddCardScannerViewControllerC010goToManualfE004cardG6ResultySo0b15CardsRecognizerN0CSg_tF + 249 19 DumaPay Consumer iOS 0x0000000105623d2e $s20DumaPay_Consumer_iOS28AddCardScannerViewControllerC02oneF15ManuallyClicked6senderyyp_tF + 62 20 DumaPay Consumer iOS 0x0000000105623d8c $s20DumaPay_Consumer_iOS28AddCardScannerViewControllerC02oneF15ManuallyClicked6senderyyp_tFTo + 76 21 UIKitCore 0x0000000111e2e834 -[UIApplication sendAction:to:from:forEvent:] + 83 22 UIKitCore 0x00000001118845b5 -[UIControl sendAction:to:forEvent:] + 67 23 UIKitCore 0x00000001118848d2 -[UIControl _sendActionsForEvents:withEvent:] + 450 24 UIKitCore 0x0000000111883888 -[UIControl touchesEnded:withEvent:] + 583 25 UIKitCore 0x0000000111e6751e -[UIWindow _sendTouchesForEvent:] + 2547 26 UIKitCore 0x0000000111e68c02 -[UIWindow sendEvent:] + 4079 27 UIKitCore 0x0000000111e47346 -[UIApplication sendEvent:] + 356 28 UIKitCore 0x0000000111f178c3 __dispatchPreprocessedEventFromEventQueue + 3232 29 UIKitCore 0x0000000111f1a1e9 __handleEventQueueInternal + 5911 30 CoreFoundation 0x0000000108c07c11 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 31 CoreFoundation 0x0000000108c07493 __CFRunLoopDoSources0 + 243 32 CoreFoundation 0x0000000108c01b4f __CFRunLoopRun + 1231 33 CoreFoundation 0x0000000108c01332 CFRunLoopRunSpecific + 626 34 GraphicsServices 0x000000010f1222fe GSEventRunModal + 65 35 UIKitCore 0x0000000111e2d1d2 UIApplicationMain + 140 36 DumaPay Consumer iOS 0x0000000105609bdb main + 75 37 libdyld.dylib 0x000000010a883861 start + 1 38 ??? 0x0000000000000001 0x0 + 1 )

Platform information

  • OS version: iOS 12.2 beta 2
  • Library version: 4.1.0
  • Language: Swift 4.2

Appending text.

I have a case where I'm trying to ender a numeric value, and appending a string at the end.. Can't get to get it working, and the documentation is not obvious..

Example:
Input 1 should look like 1 pts, and 2000 as 2000 pts..

I tried doing something like [0…]{ pts}, and multiple other combinations. What would be the way to format this text?

Multiple masked text fields

First off, awesome library. Easy to use and works really well :) 👍

Now, am I right, that, if I wanted to implement multiple masked text fields, I'd have to add a MaskedTextFieldDelegate object for each one?

Whitespace symbols as required

I figured out that if I have this mask "[0] [9]" than there is a issue
Type to textfield "1 2" - OK
Type to textfield "1" - OK
Type to textfield "1 " - Not OK

Whitespace characters are treated as required symbols, it shouldn't be like this because it isn't obvious
It should be OK for string "1 "

How to apply mask to existing text?

Hi,

What i i have define mask and delegate, and want to set pre-defined tex to text field?

When i do - myTextField.txt = "12345678" mask is not applied.

MaskedTextFieldDelegate не реагирует на ввод

Вот мой код:

let maskedDelegate = MaskedTextFieldDelegate(primaryFormat: "[0000] [0000] [0000] [0000]")
textField.delegate = maskedDelegate

При вводе текста не применяется маска, но метод maskedDelegate.put работает.

Использую Carthage, если это имеет значение.

Symbol acceptance

According to the documentation _ and - accept any digits or letters, I understood that it would not add anything else, like punctuation, spaces, etc...
And it seems to not be adding it, but still counting as a symbol or something like that.

Using the mask
"[---] [---] [---]" (it is for passports, basically can have anything)
Wields strange results, if I only use numbers and letters everything goes ok, if I use space or any punctuation symbol it adds a space and jumps to the next brackets group.

I tried with
"[---]-[---]-[---]"
And it adds the -, that's why I think that it goes to the next group.

P.S.: Not related, but you did not update the documentation to reflect the removal of PolyMaskTextFieldDelegate

Wrong mask attached after editing

I have following masks set:
self.login.affineFormats = [ "{+7} ([000]) [000] [00] [00]", "{8} ([000]) [000]-[00]-[00]" ]

When i type a phone number with +7 mask and then edit the value within ([000]) mask switches to 8 instead of +7 and then 7 is put inside ([000])

Question

Are you still maintaining this framework?

'DidEndEditingReason' is not a member type of 'UITextField'

Thank you so much for this library - I'm using both Android and Swift versions, and I love it. I did run into a little problem though on this version:

Line 167 of "MaskedTextFieldDelegate.swift":
'DidEndEditingReason' is not a member type of 'UITextField'

Assuming this is just a syntax change. Could you update, or tell me what to do to resolve?

Thanks!!!

Use without delegation

Hello,

I've been using this as recommended with the delegate, it works great but now I'm trying to use this without the delegate as I need to use another one. I want to use this but I can make it work with multiple mask and affine strategies. Is there a quick way to achieve it ?

Обрыв событийной модели при изменении текста

Добрый день. Во первых хочется сказать спасибо за отличную библиотеку.

Столкнулся с тем, что MaskedTextFieldDelegate в методе

open func textField(
        _ textField: UITextField,
        shouldChangeCharactersIn range: NSRange,
        replacementString string: String) -> Bool {
        
        let extractedValue: String
        let complete:       Bool
        
        if isDeletion(
            inRange: range,
            string: string
        ) {
            (extractedValue, complete) = self.deleteText(inRange: range, inField: textField)
        } else {
            (extractedValue, complete) = self.modifyText(inRange: range, inField: textField, withText: string)
        }
        
        self.listener?.textField?(
            textField,
            didFillMandatoryCharacters: complete,
            didExtractValue: extractedValue
        )
        let _ = self.listener?.textField?(textField, shouldChangeCharactersIn: range, replacementString: string)        
        return false
    }

всегда возвращает false, что не дает сработать событиям ни через NotificationCenter ни через actions for controlEvents. хотя в этом методе так или иначе изменится свойство text у textField.

Возможно решение не самое лучшее, но как временную заплатку у себя поправил, добавив перед возвратом вызов поста события в NotificationCenter и вызов actions для события editingChanged

open func textField(
        _ textField: UITextField,
        shouldChangeCharactersIn range: NSRange,
        replacementString string: String) -> Bool {
        
        let extractedValue: String
        let complete:       Bool
        
        if isDeletion(
            inRange: range,
            string: string
        ) {
            (extractedValue, complete) = self.deleteText(inRange: range, inField: textField)
        } else {
            (extractedValue, complete) = self.modifyText(inRange: range, inField: textField, withText: string)
        }
        
        self.listener?.textField?(
            textField,
            didFillMandatoryCharacters: complete,
            didExtractValue: extractedValue
        )
        let _ = self.listener?.textField?(textField, shouldChangeCharactersIn: range, replacementString: string)
        
        NotificationCenter.default.post(name: .UITextFieldTextDidChange, object: textField)
        textField.sendActions(for: .editingChanged)
        
        return false
    }

Что думаете на этот счет?

Fixed symbols in the mask

It will be great to have the ability of fixed symbols using.

For example I need the mask for the phone number: +7 (111) 111-11-11
So according to documentation I can to create mask for this case: +7([000])[000]-[00]-[00]
And that's alright. But I need the user can't clear fist two symbols (+7). So every time "+7" have to be always visible in the text field.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.