X
X
XenK2017-09-06 06:30:27
Yii
XenK, 2017-09-06 06:30:27

Yii2 two models in a form?

There are two different actionCreate() , in one the name of the product is created (one Name field ), in the other the cart (fields: Name, Type, Product ), the Product itself has a dropDownList , with a selection of all products.
I want to make it so that when, for example, the last value in the dropDownList ("Add a new product") is selected, an additional one appears. field, when you click on it, the Name field from Product appears already , to add a new product and then add the product_id to this created cart.
What is the best way to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
oh, 2017-09-06
well @AnneSmith

why do you need to create and click "additional field" if you can show the Name field by changing the dropdown value?
draw what exactly you want to get as a result - and we will not have to guess, and it will be clearer to you what you are actually doing
if we talk about how to do it simply, then a complete form is made in html with all the fields that can needed, and then javascript opens and hides the fields by changing the values ​​​​of other fields - dropdowns, checkboxes, radio buttons, etc.
The "basket" can be a hidden input text field, into which you can add your id's separated by commas when choosing different products,
then send the completed form to the server and there you do the mapping of the form fields you need according to your models
keep it simple

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question