you have to move javascript logic to a proper file. You have to create a fields.js file and put this logic there