Sidebar menu to hide or expand parts of a form
I think, your improved code looks okay temporarily until you try to add new functionalities. 

A function should do only one thing. 

Trying to add a custom functionality to your improved code would result in clutter and more if else statements.