Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • J JVFloatLabeledTextField
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 26
    • Issues 26
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Jared Verdi
  • JVFloatLabeledTextField
  • Merge requests
  • !45

Added ability to disable pasting to JVFloatLabeledTextField

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/ArtSabintsev/master into master Feb 06, 2014
  • Overview 2
  • Commits 1
  • Pipelines 0
  • Changes 2

Created by: ArtSabintsev

There exist certain situations where I, and others, may want to disallow pasting in a textfield. For instance, if I want the last 4 digits of someone's SSN, or their phone number, I only want to allow numbers in the text field. There are three ways of enforcing this condition:

  • Using UIKeyboardTypeNumberPad.
  • Another way, is by monitoring every character that gets entered Using - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string.
    • This second option an ugly way of doing it.
  • Logic, coupled with passive or active alerts

However, the first two options can be circumvented by allowing data from a different field to be pasted into this field. The third option is just annoying. A cleaner, more elegant manner of implementing this feature is to disallow pasting into the textfield. This can be achieved using the canPerformAction:withSender UIResponder method. However, this method must be implemented inside a subclassed UITextField. I have done just that within JVFloatLabeledTextField .h/.m.

As I use CocoaPods to manage your repo, and I'm not wanting to subclass JVFloatLabeledTextField directly within my project (e.g., lazy), I decided to create this change and submit it to you for your evaluation.

Hopefully, I've presented my case, and that you'll consider adding this change.

Thanks for your consideration!

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/ArtSabintsev/master