M
M
MarkBogrov2017-05-17 01:42:31
Yii
MarkBogrov, 2017-05-17 01:42:31

Yii2: How to create an object of a related model asynchronously while creating an object of one model?

Faced with a very entertaining problem, when creating a client in the system, make it bind to a city, there is no desire to drive all the cities of the world into the database, so we created our own class of cities with CRUD, for manual loading.

Question: How to make an elegant solution, when in the form of creating a client, to make it possible to add the missing city elegantly and unobtrusively with Ajax?

The mechanics of the process is clear to me, I send an Ajax request to the create action of the city controller with the data of the missing city.

The question is, if there is some widget for this, that would somehow fit the add form (perhaps in a modal) of the city with its three fields (Ru / En / Url) into the user creation interface, and then update the contents of the DropDown selector with cities, where will the newly added city appear?

I would be grateful for any ideas on this matter!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-05-17
@webinar

We turn off the select with cities in Pjax, run pjax, after the action of adding a city returned "ok".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question