Used the startEditing() method

The old code was doing incorrect things for empty text fields.
Switched end condition