Different Form Fields According To A Select

Hello, I’m trying to make a form like this

Select Dropdown

"Pick a type"

Doctor

Sector

If someone chooses Doctor I want this fields to appear:

Name

Surname

Address

If someone chooses sector I might use instead

Description

Floor

So my question is, can I do this on a single form, or maybe can I load a form according to the select?

Thanks in advance.

This is pretty basic JS.

You just create onchange handler for dropdown where show or hide other inputs (or even the whole forms).

The only tricky part here is validation, but it depends on how you store these forms.

Is there a way I can renderPartial on onchange?

Sure, just make an ajax request to an action that does renderpartial on ajax.

Dont forget to render required form if the select is already set to some value (update scenario)