Yii2 assign values according to the previous ones - yii2

I have a 2 dropdown menus, which is in my form. I have created 2 databases: category and item, their structure is below:
category database:
id, name
item database:
id, category_id, name, price.
I manually stored data inside of it (in the category I stored Computers, Cars and Phones and according to the categories id I manually stored items.
So I have 2 dropDownMenus, one is category name and the other is item name. Here is what I need to do:
If the user selects f.e computer categories, automatically items dropdownmenu should show computer items and so on. Could someone explain how it can be solved? I guess I should show that the item dropdown menu should show the values according to the category_id, but i'm not sure.
Here is my view file, where is those 2 dropdown menus:
<?= $form->field($model, 'code') ?>
<?= $form->field($category, 'name')->dropDownList(
ArrayHelper::map(Category::find()->All(),'id','name')) ?>
<?= $form->field($item, 'name')->dropDownList(
ArrayHelper::map(Item::find()->All(),'id', 'name')) ?>
I hope that you understand my problem, thanks for any help.

Related

Primefaces Treenode How to select father node only?

Is there anyways to select father node without its children in Primefaces treenode?
I am using Primefaces treenode to display a product category, but not all products belong to children categories. For example, a product belongs to category 1.1.1, but another belongs to 1.1.
I want to update the product's category, but when I select father node, its nodes will be selected too.
This is when I select father category:
This is what I want it to be:
Please help me, thank you.
p/s: I want to use checkbox.
See the documentation: https://primefaces.github.io/primefaces/10_0_0/#/components/tree?id=tree
Look at the propagateSelectionUp and propagateSelectionDown properties. You want to turn them to false to get the behavior you want.

How to append serial number in activeForm form attribute

Trying to display questions from table, I want display serial number before that question.
I tried but I am getting number in one line and question is other line.
EX:
<?= $index+1 . $form->field($practiceTest, "[$index]question")->textarea(['readonly'=> true]) ?>
Can any one give an idea how to display number after question like.
Ex: 1. question
You can try to use Ordered List in case when you need to get numbers calculated.
<ol type="1">
<!-- I guess here you iterate to get index -->
<li>
<?= $form->field($practiceTest, "[$index]question")->textarea(['readonly'=> true]) ?>
</li>
<!-- Finish iteration -->
</ol>
Hope it will helps

Magento Products create menu sub selections

I have a Category (Test-Category) I have 3 products inside of it. (Magento 1.9.3.3)
This test category is included in my main menu. Right now I have that Category page displaying its 3 products.
I would like to have those products show as items in the menu under this category.
Test-Category
--Product 1
--Product 2
--Product 3
Those items would link directly to the product pages.
I have managed to do this by creating categorys for each product, but then the link displays as a category page with 1 product in it. Maybe it's easier to redirect what this "category page" displays?
I have figured this out by adding a custom URL to the product category page that is the product URL

How to show/hide anchor tag on the basis of database value

In my aspx page i have listview in which i have three tags one for hotel invoice second for package third for vehicle all 3 are visible now what i want if at first time user create hotel invoice then in database its invoice type is saved next time when user open that page on the basis of invoice type only that tag should be visible like if user create hotel invoice then only hotel invoice tag should be visible and if vehicle invoice was created then only vehicle invoice tag should be visible other two should be invisible.
Can anyone help me in this issue.
thanks in advance for your help.
<a style="style='<%# DataBinder.Eval(Container.DataItem, "Class.YourDbValue") == null ? "display:block;": "display:none;"%>'>>"
#AkshayRandive I think what he means is that his InvoiceType is based on the 3 values
<%
if(DataBinder.Eval(Container.DataItem, "Class.InvoiceType") != null)
{
Hotel Invoice
}
%>
Something like this should only show Hotel Invoice when you have an existing type.
You could make the link value dynamic but you can figure that out yourself.

How to control column headings in the NEW/EDIT views based on the CATEGORY selected from a drop-down list. Ruby on Rails w/ MYSQL

Two models:
category has_many: components
component belongs_to: category
The CATEGORY table defines variable names for different component types:
TYPE, VAR1, VAR2, VAR3, ...
Insulator, Voltage, Height, Material, ...
Current Transformer, Voltage, Ratio, Indoor, ...
In the NEW/EDIT views for the COMPONENT model, the user will first section the CATEGORY from a drop-down list. Based on the CATEGORY selected the column headings and field labels in the form(s) need to dynamically update to indicate the variable names associated with the selected CATEGORY.
i.e. IF the user selects CATEGORY = Insulator THEN the field labels for VAR1 ... VAR3 are Voltage, Height, Material, etc.
I assume this will be controlled in the _form.html.erb of a typical scaffold. I am looking for a recommended technique.
Thanks in advance any information.
Changing a form in response to a user selecting a different option in a select tag is probably best done by Javascript. This allows for execution on the client side, which will be faster than a trip back to the server.
I would recommend placing the different form fields inside a div tag that is hidden when the page loads. Each of the combinations of categories can be toggled to show in the form by binding to the Javscript onChange event on the select tag.
Here is more information on the select tag: http://www.w3schools.com/jsref/event_onchange.asp