How can I change the input in a field based on conditions?