How to fill initial values for select on HTML form from database?

I’m new here. Can you help me with a newbie question, please? Maybe provide a link to solution.

I have a RESTful service and a web form for editing a model (e.g. user preferences). I want to prepare initial values on form. I request “new” model from the service and it sends me a JSON that contains object with initial values set (for example gender or birth date). It is easy to fill text inputs with those values. But also form has several select elements which should be filled with options from a database. And then I can set appropriate initial options (id) from the model for those select elements.

What is the way to do this?
I see couple ways:

  1. Service might send options together with the model in JSON;
  2. Form can request options itself before getting initial values (but it is another request and if form has several selects it is several requests).

Is there any conventional or best practice way?

Source: json

Leave a Reply