-2

I have a username textfield with textContentType as username and another with the password. Along with this, I had an email text field without any textContentType. When saving the credentials email is being saved as username but not the value from username text field.

usernametextfield.textContentType = .username

emailtextfield.textContentType = UITextContentType(rawValue:"")

How to save the username instead of email?

Kalyan
  • 263
  • 5
  • 22
  • please share your code – Jawad Ali Feb 06 '20 at 12:51
  • Added the two lines of code that am using in the question itself. Thanks – Kalyan Feb 06 '20 at 13:03
  • When you access the textfield values then those got access as a plain text and there is no relation with `.textContentType` so there should not be any issues, ideally!! However if you can share more code showing your save functionality then it would be easy to understand this issue!! – RJ168 Feb 06 '20 at 13:10
  • @RJ168 we are not saving anything at our end. We are implementing autofill functionality. So, our text fields textContentType is set as .username for username field as mentioned above and for email as empty value. So, iOS handles saving the username and password in iOS keychain. When doing this password is being saved correctly but not the username. It is taking email as username and saving in iOS keychain but it should take username. – Kalyan Feb 06 '20 at 13:17

1 Answers1

2

Finally found why this .textContentType is not working as expected. In the form, if there are multiple fields to be entered, then the username/email, password/confirm password fields should be the last input fields in the form. This is how I was able to fix my issue.

Kalyan
  • 263
  • 5
  • 22