Yii2 Lesson - 20 Dependent Drop Down Lists

Yii2 Lesson - 20 Dependent Drop Down Lists

Uthpala Heenatigala

9 лет назад

61,726 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

The Rocket Club
The Rocket Club - 05.10.2022 15:53

you just copy the code ,its hard to type atleast yu could have given the link where your code is and we can re edit in according to our work......some of us are slow learners

Ответить
kuvar singh
kuvar singh - 07.04.2020 16:58

thankyou so much sir

Ответить
MusicXs
MusicXs - 05.12.2019 16:28

How to make three levels?

Ответить
TopSh
TopSh - 27.11.2019 17:13

ty dude!)

Ответить
Kleider González
Kleider González - 21.06.2019 22:38

Very Good.! Tanks. ;)

Ответить
Surendra Ojha
Surendra Ojha - 29.04.2019 13:04

500 internal server error guys please help

Ответить
Yogesh Sharma
Yogesh Sharma - 16.04.2019 18:50

$countBranches = Facultypaper::find()
->select(['facultypaper.*'])
->leftJoin('courses', 'facultypaper.faculty_paper_course_id = courses.course_id' )
->where(['paper_faculty_id' => $facultyid])
->andwhere(['faculty_paper_semester_id' => $id])
->count();



$branches = Facultypaper::find()
->select(['courses.course_id' ,'courses.courses_name'])
->leftJoin('courses', 'facultypaper.faculty_paper_course_id = courses.course_id' )
->where(['paper_faculty_id' => $facultyid])
->andwhere(['faculty_paper_semester_id' => $id])
->all();


if ($countBranches > 0)
{
echo "<option>Select Course</option>";
foreach ($branches as $branch)
{

echo "<option value='".$branch->faculty_paper_course_id."'>".$branch->courses.courses_name."</option>";
}
}
else
{
echo "<option>-</option>";
}


this i my code for relational dropdown but i am not able to get second table columns its show only first table column please help me how to join bot table. Here courses_name show error

Ответить
mehrad gitimehr
mehrad gitimehr - 15.10.2018 23:44

It was perfect .. thank you very much

Ответить
Manoj Agrawal
Manoj Agrawal - 29.09.2018 12:26

Good job ... you have explained it very well.
I have a question , is there any way to add "Expiry date" in RBAC.
Can you also create one video on kartik tree view control.

Ответить
Mounika Lakshmanan
Mounika Lakshmanan - 28.06.2018 12:19

how to make an dependent drop down list search in grid view?

Ответить
Guillermo Romano
Guillermo Romano - 14.07.2017 23:38

Hi Guys, I wanna add some code lines because I loss a lot of time with this tutorial. Alwais the fields populated all data.
The code: (Remenber i didn´t use the same name in tables of the DB)(Change for that u r using)

'onchange'=>'$.post("index.php?r=branches/lists&id='.'"+$(this).val(),function( data ){
$( "select#departments-branch_id" ).html( data );
});
'

Ответить
Immanuel Production
Immanuel Production - 14.07.2017 06:42

hello
i want to ask, how about to make dependent auto suggest dropdown search?
i'm newbie in this framework :)

Ответить
Zero Service
Zero Service - 15.06.2017 10:10

ขอบคุณครับ Thank you.

Ответить
Rahul Bisht
Rahul Bisht - 22.02.2017 16:44

Good Tutorial to learn.One question that i want to ask, first time when the page loads it shows all value in second dropdown list ,but when option is choose from first it changes as coded.
So how to hide all lists in second dropdown when nothing is selected in first?

Ответить
Draga Poetra
Draga Poetra - 13.02.2017 12:12

Hello i got problem
when i save the data in database
the input of drop down identified by id
how to change the id into Name of value?

Ответить
denis setianto
denis setianto - 02.12.2016 09:48

thanks for the tutorial, but i have a similiar case like this, dependent dropdown to checkboxlist. if i choose one value from the dropdown the checkbox will generated by the key value.

but when i want to save, i cant get the value of the dependent checkbox.

this my code part from view and controller.

- view
<?= $form->field($model, 'cp_countrytarget')->dropDownList(
ArrayHelper::map(\app\models\Countries::find()->all(), 'countries_id', 'name'),
[
'prompt' => 'Select Country',
'class' => 'dependent-input form-control',
'onchange' => '$.get("index.php?r=tbcampaign/countries&id='.'"+$(this).val(), function(data) {
$("#tbcampaign-cp_statetarget").html(data);
});'
]); ?>

<?=$form->field($model, 'cp_statetarget')->checkboxlist([]);?>

- controller

public function actionCountries($id)
{
$states = States::find()>where(['country_id' => $id])>all();

foreach ($states as $state)
{
return Html::checkboxList('Tbcampaign[cp_citiestarget][]',[],ArrayHelper::map($states, 'name', 'name'), []);
}

hope i can get any solution, thanks before :)

Ответить
Якуб Якубов
Якуб Якубов - 24.11.2016 10:42

so at the moment , when company is not chosen , branches filled by some trash?

Ответить
Kunal Jog
Kunal Jog - 22.11.2016 10:23

How can we update dropdown on page load?

Ответить
Test
Test - 28.10.2016 14:06

hello, if i use PrettyUrl how i should send requests?

Ответить
parth shah
parth shah - 06.10.2016 16:28

which editor you are using?

Ответить
Redha H
Redha H - 01.10.2016 04:55

Thank you so much, you helped me a lot with this lecture,
never imagined the solution of echoing the <option> value and how the javascript post handle the html code to populate the dropdown list, how did you come up with such a brilliant idea?

I'm using the concept of your post to selected list of value, I'm using for a barcode scanner input, since it uses text input, I don't use the onchange from the yii2 but I'm using the javascript if the id of the text input form changes then pass the barcode value and then the post pass the value generated from the controllers that you've shown above, only since I can't overcome the distinct issue, I used findBySql rather than find, much more familiar and easy to understand if the person is common with using sql queries

Ответить
Everlyn Mbula
Everlyn Mbula - 01.09.2016 18:41

How do I do one for three dependent drop downs ?

Ответить
Jonathan B
Jonathan B - 27.06.2016 23:33

Rather going to the DB twice we can just check if the branches exist.,
/**
$count = Branches::find()
->where(['companies_company_id' => $id])
->count();
*/
$branches = Branches::find()
->where(['companies_company_id' => $id])
->all();

if ($branches)
{
foreach ($branches as $branch) {
echo '<option value="' . $branch->branch_id . '">' . $branch->branch_name . '</option>';
}
} else {
echo "<option> - </option>";
}

Ответить
Bogdan Baerov
Bogdan Baerov - 21.06.2016 16:59

Respect

Ответить
Pablo Garay Cofré
Pablo Garay Cofré - 13.06.2016 11:12

Woow... it's awesome...
thaaank ;)!!!

Ответить
cfpmx
cfpmx - 29.05.2016 02:13

I want to update a GridView when I select a DropDownList, how can I do that? Thanks :)

Ответить
владимир васин
владимир васин - 16.05.2016 16:02

hi. Your lessons is very good. I have some questions. I have 403(Forbidden) error. This fixed by adding some rules in contoller behaviors method, but i cant understand how. Can you share your BranchesController, pls? Or explain, how fix this problem?

Ответить
cfpmx
cfpmx - 13.04.2016 00:59

I want to update a text input value according to the selected item in the dropdownlist, how can I do that? Thanks :S

Ответить
Knox Knox
Knox Knox - 03.02.2016 21:01

Very useful

Ответить
Jan Elholm
Jan Elholm - 03.01.2016 20:16

Very good tutorial. Is it possible to use the same methodology to make a dependant sortable input? Ie. when selecting from a drop down list, the sortable input changes content. I think this would require 2 $post - one for updating the list items and one for updating the id list. Anyone tried this?

Ответить
Макс макс
Макс макс - 30.12.2015 02:15

$countBranches and $brances? 2 query? realy?

$branches = Branchs::find()
->where(['companies_company_id' =>$id])
->all();

if (!empty($branches)) {
//do something... make options list
} else {
//make empty list
}

Ответить
Ashish Rastogi
Ashish Rastogi - 22.12.2015 12:54

hi, code id not working in my app. could you please share the your code ? thanks

Ответить
Branislav Kutnik
Branislav Kutnik - 06.11.2015 16:52

you are using the jQuery function $.post, so why are you passing "id" as a paramater for action when there is possibility of use slightly different expression as follows - $.post(someUrl,{"id" : $(this).val()}, function(data){ //code to replace html}), and in controller yii::$app->request->post('id'), for example?

Ответить
Bruno Reis
Bruno Reis - 12.10.2015 17:35

Did you/someone have the same solution using kartik-v select2 and depdrop widgets.

Thanks

Ответить
Garegin Davtyan
Garegin Davtyan - 27.09.2015 14:10

Hello!

I want to know how can i create 'views' folder which can be used from backend and from frontend sides. 
I create 'views' folder in the base common folder (common\views) and create file inside this folder(common\views\_selectOptions.php). But i could'n do render partial from backend.
thanks:)

Ответить
Jowo Sentono
Jowo Sentono - 19.08.2015 19:21

Hello, in this part lesson i have some problem, i was create 2 company, every company has 2 branch. but when select company id 1 ,still show all branch id, where is my fault, please help :)

Ответить
Team VOSPL
Team VOSPL - 11.06.2015 13:06

Thanks for such a detailed tutorial, I am facing one problem in this, when updating the details, we have to again select the parent dropdown

Ответить
cachwahed
cachwahed - 27.05.2015 01:29

Hi, thanks for share, just there is a strange behaviors when generating js code, you might end up with encoded code like: &quote;index.php?r=branches...&quote;
to avoid this behaviors I used registerJs like the following:
'onchange' => $this->registerJs('
$(\'#departments-companies_company_id\').change(function(){
$.post("index.php?r=branches/lists&id="+$(this).val(), function(data){
$("select#departments-branches_branch_id").html(data);
});
});
')
the rest of code remain same, and nothing extra to import.

Ответить
Naveen Yadav
Naveen Yadav - 19.05.2015 08:31

Hello,How can I achieve this "auto search drop-down" select box because I am not getting error.
Hope you help me asap. Thanks

Ответить
Абдурахман Таскибаев
Абдурахман Таскибаев - 19.05.2015 00:46

Assalam aleykum! Your tutorials are very good. in 2 days i gained such information about YII2 which i couldnot get in a month by searching all articles. And i got queston: what chrome extention do you use to check get/post request? In the this video u started using  it at 3.07.

Ответить
Thiago Augustus de Oliveira
Thiago Augustus de Oliveira - 16.05.2015 21:18

I was getting forbidden return message than I just added in the branchesController behavior method the actionLists in the rule action list. But this is a very good tutorial. Congratulations...

Ответить
Marian Zburlea
Marian Zburlea - 02.05.2015 01:48

CTRL + SHIFT + D in sublime duplicates the selection or the line your cursor is currently in. No more copy/paste for you:)
You're welcome!

Ответить
Stanimir Stoyanov
Stanimir Stoyanov - 14.03.2015 14:33

Thank you for your great tutorials! One question though: Why you're pre-populating the branches dropdown with all available branches when you'll overwrite it later? It should be an empty drop-down or even hidden dropdown, which will only be visible if you have a company selected.

Greetings from Europe!

Ответить
Carlo Pesce
Carlo Pesce - 13.02.2015 17:08

Thank you very much your tutorials are always really very helpful.
I'm really sorry to bother you.
Suppose you have done a dependent drop down list also for branches to show the related departments.
If you select the company name, you have all the related branches and selecting a branch, all the departments. And that's ok. If you don't press create, but you change your mind and change the company name, the branches is changing but the department remains the same. Is there a polite way to "reset" also the department when the company changes?
thank you so much

Ответить
أنيس أبوحميد
أنيس أبوحميد - 26.01.2015 17:03

Thanks, very nice & very Simple, 

Please, I would ask about RBAC Lesson, is finished Lesson as part 1 & part 2?

Thanks a lot ^_^

Ответить
VĂN DŨNG TRẦN
VĂN DŨNG TRẦN - 22.01.2015 08:37

thank

Ответить