Refactor common input field logic into a directive