lionheart / openradar-mirror

A mirror of radars pulled from http://openradar.me/.
246 stars 17 forks source link

33634848: Autofilling an email to a UITextField with UITextContentType of email doesn't send correct information to UITextFieldDelegate shouldChangeCharactersInRange function #18086

Open openradar-mirror opened 7 years ago

openradar-mirror commented 7 years ago

Description

Summary: I have a UITextField, it's textContentType is set to UITextContentType.emailAddress and when the field is selected, email addresses are properly shown above the keyboard. However I have a limited set of characters allowed in this UITextField and that is gated by the textfield's delegate implementing textField:shouldChangeCharacterIn:replacementString. One of those invalid characters is a space.

Unfortunately, when tapping the suggested email address above the keyboard, the replacementString sent to the delegate function is " " and not "the@email.address". Also what is finally inserted is "the@email.address " with a trailing space at the end. This functionality makes it challenging to validate input and also erroneously inserts spaces after an email address in a field designated only for email addresses.

Steps to Reproduce:

  1. Create a UITextField
  2. Set the text field's textContentType to .emailAddress
  3. Set its delegate
  4. Implement func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool in the delegate
  5. Select the text field
  6. Try to insert the suggested email address
  7. Note that the string sent to func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool is " " and not the email address.

Expected Results: Should receive the actual email address in the delegate function without a trailing space.

Observed Results: The delegate function is told that a single space is attempting to be inserted, then if it returns true, the email address plus a space is inserted, if it returns false, nothing is inserted.

Version: iOS 11, Beta 4

Notes:

Configuration: Tested so far on an iPad Air 2 and an iPhone 6s Plus running iOS 11 beta.

- Product Version: iOS 11 Beta 4 Created: 2017-07-31T21:50:32.771510 Originated: 2017-07-31T00:00:00 Open Radar Link: http://www.openradar.me/33634848

shubham-mandal commented 6 years ago

@openradar-mirror Facing the same issue here. Did you get any solution for it ? It will be helpful if you can post the solution too. Thanks.

voidless commented 6 years ago

Worked around it by returning true for single space replacement when textField.text is empty.