Html : view an id outside its parent id - html

I have this collapse in my web app :
<div id="accordionExample" >
#foreach ($mysection as $section)
<?php $sec_name='home.sec'.$section->section_name ;
$collaps_count++;
$nf = new NumberFormatter("en", NumberFormatter::SPELLOUT);
$numbers_name=$nf->format($collaps_count);
$numbers_name=ucfirst($numbers_name);
$collapse_id='collapse'.$numbers_name;
$heading='heading'.$numbers_name;?>
<div class="card">
<div class="ard-header py-0 px-0" id="$heading" style="border: none">
<button class=" btn w-100 text-right bg-light " type="button" data-toggle="collapse" data-target="#{{$collapse_id}}" aria-expanded="true" aria-controls="{{$collapse_id}}" >
<h5 class="">{{__($sec_name)}}</div></h5>
</button>
</div>
<div style="height:5px"></div>
<div id="{{$collapse_id}}" class="collapse <?php if($collaps_count == 1) echo 'show'?>" aria-labelledby="{{$heading}}" data-parent="#accordionExample">
#foreach ($course->Lession as $lession)
#if ($section->section_name == $lession->section_name)
<div class=" card-body flex-row d-flex justify-content-between">
<div>- {{$lession->$less_lang}}</div>
#if ($lession->id==$order->lession_id)
<div class="text-left ml-2"><i class="material-icons" style="color:green">visibility</i></div>
#else
<div class="text-left ml-2"><i class="material-icons" style="color:grey">visibility</i></div>
#endif
</div>
#endif
#endforeach
</div>
</div>
#endforeach;
</div>
<!-- End of Lessionss Card -->
</div>
The problem is while looping the collapse :
first row is start inside (accordionExample) id correctly.
second row start outside (accordionExample) id.
this row start with the parent of (accordionExample) id as show in image :

You have 2 errors in your markup:
Closing div inside button tag:
<h5 class="">{{__($sec_name)}}</div></h5>
Replace by
<h5 class="">{{__($sec_name)}}</h5> OR <h5 class=""><div>{{__($sec_name)}}</div></h5>
Extra div at the end.

your foreach loop is starting after #accordionExample but at the end there is 2 closing tag of div.
#endforeach;
</div>
<!-- End of Lessionss Card -->
</div>
this should be change to
</div>
#endforeach;
<!-- End of Lessionss Card -->
</div>
``

Related

handle Onclick event from Vue to Vuex

I'm switching from vue to vuex and I'm having trouble implementing an onclick event. I'm using bootstrap collapse to create 3 div. Each div has a button to show the collapsible elements inside. With vue I'm taking the data from an api request. I want every single button to open its parent div. Currently every button open all the three divs. When using vue I simply wrote this:
methods:{
//set expand to true foreach player card,
//set open to true foreach plus button
playerCardCollapse(index) {
this.teams = this.teams.map((item, i) => {
item.expanded = !item.expanded
item.open = !item.open
if (i !== index) {
item.expanded = false
item.open = false
}
return item
})
},
},
This is my template:
<!-- Container Card -->
<div v-for="(team, i) in teams" :key="i" class="col-6">
<div class="row mb-2 team-default align-items-center" style="height:106px;">
<div class="col-2 section">
<img class="rounded-circle" :src="team.team_img" style="border:2px solid #fff;box-shadow: 0 2px 31px 0 rgba(0, 0, 0, 0.23);">
</div>
<div class="col section team end">
<p class="intestazione">Team Name:</p>
<p class="result">{{team.team_name}}</p>
</div>
<div class="col-2 section end">
<button type="button" class="btnProfile" data-bs-toggle="collapse" data-bs-target="#profile-row" :aria-expanded="team.expanded" aria-controls="profile-row" #click.prevent="playerCardCollapse(i)">
<div class="plus-icon" :class="{open: team.open}"></div>
</button>
</div>
</div>
<!-- Collapsed -->
<div v-if="team.player.length>0">
<div class="collapse show" :class="{show: team.expanded}">
<div v-for="(p, j) in team.player" :key="j" class="row team-default mt-2 mb-3" id="profile-row">
<div class="col-2 section">
<div class="player-img-container">
<img class="rounded-circle player-img" :src="p.profilePic">
<img class="rounded-circle flag-img" src="https://picsum.photos/31/31">
</div>
</div>
<div class="col section team end">
<p class="intestazione">Team {{p.role}}</p>
<p class="result">{{p.name}}</p>
</div>
<div class="col-4 section end">
<button class="btnProfile-cta">Visualizza Profilo</button>
</div>
</div>
</div>
</div>
</div>
But with vuex I don't know how to implement this playerCardCollapse().
Hope someone could help (I don't know if you need more code snippets)

CSS moving button to right side

I am using bootstrap and angular material for the UI. In one of my div. I want to move my button to the right side but when I do apply class "float-right" it is going behind the other div.
This is the image URL https://prnt.sc/y0xn90
Below is the code.
<div class="card-body">
<div class="tab-content">
<!-- /.tab-pane -->
<div class="active tab-pane" id="timeline">
<div>
<button mat-raised-button color="primary">Add Treatment</button>
</div>
<div>
<ul class="timeline" *ngFor="let treatment of patientTreatments">
<li class="timeline-item bg-white rounded ml-3 p-4 shadow">
<div class="timeline-arrow"></div>
<h2 class="h5 mb-0">{{treatment.title}}<span class="float-right" style="cursor: pointer;">
<mat-icon>edit</mat-icon>
</span></h2>
<span class="small text-gray"><i class="fa fa-clock-o mr-1"></i>{{treatment.treatmentDate}}</span>
<p class="text-small mt-2 font-weight-light">{{treatment.summary}}</p>
<div *ngFor="let files of treatment.treatmentFiles">
<img src="" alt="Treatment image">
</div>
</li>
</ul><!-- End -->
</div>
<!-- The timeline -->
</div>
<!-- /.tab-pane -->
<div class="tab-pane" id="settings">
111
</div>
<!-- /.tab-pane -->
</div>
<!-- /.tab-content -->
</div><!-- /.card-body -->
you can use the display flex property with the width 100% and u can push left or right side with flex-end/flex-start
<div style="width: 100%;display: flex;justify-content: flex-end;align-items: center;">
<button mat-raised-button color="primary">Add Treatment</button>
</div>

how to make the card add to the side, when I do foreach on php?

Card looks like this. i just want it to display to the side
Im trying to show data from my database in PHP codeigniter. the data shows fine. but the problem is that the card is going down istead to right. you can look at the image above.
i just want to make the card go to the right when i do foreach. and go down after 4/5 card.
i ve tried to move the foreach code but it looks just like that.
im using bootsrap 4
here's the code
<div class="row">
<div class="container">
<div class="card-body">
<?php
foreach ($user as $u) {?>
<div class="col-md-2 mt-4">
<div class="card mt-3" style="width:15rem;">
<img src="<?=base_url() . 'assets/img/' . $u->gambar_game;?>"
class="card-img-top img-responsive" alt="...">
<h5 class="card-title font-weight-bold "><?php echo $u->nama_game; ?></h5>
<p class="card-text"><?=$u->deskripsi_game;?></p>
<a href="<?=base_url() . 'assets/games/' . $u->link_game;?>"
class="btn btn-primary btn-block">Mainkan Game</a>
</div>
</div>
</div>
<?php }?>
</div>
</div>
you are repeating currently the whole container inside the row, but u want to repeat the cols inside the container.
Try this (loop over the col-md-2):
<div class="row">
<div class="container">
<div class="card-body">
<?php
foreach ($user as $u) {?>
<div class="col-md-2 mt-4">
<div class="card mt-3" style="width:15rem;">
<img src="<?=base_url() . 'assets/img/' . $u->gambar_game;?>"
class="card-img-top img-responsive" alt="...">
<h5 class="card-title font-weight-bold "><?php echo $u->nama_game; ?></h5>
<p class="card-text"><?=$u->deskripsi_game;?></p>
<a href="<?=base_url() . 'assets/games/' . $u->link_game;?>"
class="btn btn-primary btn-block">Mainkan Game</a>
</div>
</div>
</div>
<?php }?>
</div>
</div>
</div>
EDIT:
Your HTML structure was a little mixed up.
Try this. col-md-3 places 4 cols inside of your row, or col-md-2if you want 6 cols inside of your row. A row is max 12 cols bootstrap grid documentation
<div class="container">
<div class="row">
<?php foreach ($user as $u) {?>
<!-- col-md-2 -->
<div class="col-md-4 mt-4">
<div class="card">
<div class="card-body">
<img src="<?=base_url() . 'assets/img/' . $u->gambar_game;?>"class="card-img-top img-responsive" alt="...">
<h5 class="card-title font-weight-bold "><?php echo $u->nama_game; ?></h5>
<p class="card-text"><?=$u->deskripsi_game;?></p>
Mainkan Game
</div>
</div>
</div>
<!-- col-md-2 end -->
<?php }?>
</div>
</div>

Multiple lists with drag & drop within group

I have two divs in a parent component. And there are cards (components rendered in divs) in each of the above two divs. Each card has got a list of employees (also divs) from which I want to drag any across other cards within their own parent div.
Below image shows how my page look like:
I want the page to be able to drag employees within Pickup or Drop. For eg: move Employee1 from {Place1 To Place2} to {Place3 To Place2} I have used cdkDropList/cdkDrag, however I could not drag anything at all.
Below is my html for parent component with the Pickup & Drop divs:
<div class="row">
<div class="col-md-12">
<h5 class="bg-primary text-white">Pickup</h5>
</div>
</div>
<!-- Pickup DIV -->
<div class="row" cdkDropListGroup>
<div class="col col-md-4" *ngFor="let item of pickupCabs" cdkDropList [cdkDropListData]="item.AssignedEmployees"
(cdkDropListDropped)="onDrop($event)">
<app-admin-special-request-allocation-card [allocatedCab]="item"
(childevent)="onSpecialRequestReallocation($event)" cdkDrag>
</app-admin-special-request-allocation-card>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h5 class="bg-primary text-white">Drop</h5>
</div>
</div>
<!-- Drop DIV -->
<div class="row" cdkDropListGroup>
<div class="col col-md-4" *ngFor="let item of dropCabs" cdkDropList [cdkDropListData]="item.AssignedEmployees"
(cdkDropListDropped)="onDrop($event)">
<app-admin-special-request-allocation-card [allocatedCab]="item"
(childevent)="onSpecialRequestReallocation($event)" cdkDrag>
</app-admin-special-request-allocation-card>
</div>
</div>
Below is my html for the individual cards/routes (app-admin-special-request-allocation-card.component.html)
<div class="card bg-light shadow p-3 mb-4 bg-white corners mt-2 mb-2">
<div class="card-body text-center">
<div [class.alert-danger]="!isAllocatedSuccess" [class.alert-success]="isAllocatedSuccess" class="alert"
*ngIf="isAllocated">{{message}}</div>
<div class="row">
<div class="col text-right">
<span><b>{{allocatedCab.AllocationStatusText}}</b></span>
</div>
</div>
<div class="row">
<div class="col-md-3">
<i class='fas fa-{{allocatedCab.CabType|lowercase}}' style='font-size:30px;'></i>
<br>
<b>{{allocatedCab.Occupance}}/{{allocatedCab.Capacity}}</b>
<p><b><span>{{allocatedCab.RouteType}}</span></b></p>
</div>
<div class="row">
<p><b><span>{{allocatedCab.PickupPoint}} To {{allocatedCab.DropPoint}}</span></b></p>
</div>
<div class="row">
<p style="text-align: left"><b><span>{{allocatedCab.VendorName}} -
{{allocatedCab.CabName}} - {{allocatedCab.RegNo}}</span></b></p>
</div>
<!-- employee list -->
<div class="row" *ngFor="let employee of allocatedCab.AssignedEmployees">
<p style="text-align: left"><span class="fa fa-user"></span>
<a href="./admin#" (click)="open(content,allocatedCab,employee)">
{{employee.FirstName}} {{employee.LastName}} -
<small> {{employee.PickupDate | date: "hh:mm a"}} </small>
</a>
<i style="color:red; cursor: pointer;" class="fa fa-remove"
(click)="openConfirmation(content1, employee)"></i></p>
</div>
</div>
<div class="row">
<div class="col-md-6 pt-2 text-left ">
<span>{{allocatedCab.PickupDate | date: "dd/MM/yyyy hh:mm a"}}</span>
</div>
</div>
</div>
</div>
I think there is a mistake in your code. The cdkDropList attribute is placed in the wrong div. And the cdkDrag attribute should be given to the exact div which can be draggable. So only give cdkDropListGroup attribute in parent div and place cdkDropList attribute inside the card component. ie.
You don't need cdkDropList attribute and the following code in that element in your parent div (Pickup and Drop).
Instead, add it in app-admin-special-request-allocation-card.component.html to a new wrapping div over the employee list div.
Add the cdkDrag attribute to exact div in which employee name is rendered.
try the below code.
Parent Component
<div class="row">
<div class="col-md-12">
<h5 class="bg-primary text-white">Pickup</h5>
</div>
</div>
<div class="row" cdkDropListGroup>
<!-- remove the 'cdkDropList' attribute and [cdkDropListData]=" from below div -->
<div class="col col-md-4" *ngFor="let item of pickupCabs">
<app-admin-special-request-allocation-card [allocatedCab]="item" (childevent)="onSpecialRequestReallocation($event)">
</app-admin-special-request-allocation-card>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h5 class="bg-primary text-white">Drop</h5>
</div>
</div>
<div class="row" cdkDropListGroup>
<!-- remove the 'cdkDropList' attribute and [cdkDropListData]=" from below div -->
<div class="col col-md-4" *ngFor="let item of dropCabs">
<app-admin-special-request-allocation-card [allocatedCab]="item" (childevent)="onSpecialRequestReallocation($event)">
</app-admin-special-request-allocation-card>
</div>
</div>
Card Component
<div class="card bg-light shadow p-3 mb-4 bg-white corners mt-2 mb-2">
<div class="card-body text-center">
<div [class.alert-danger]="!isAllocatedSuccess" [class.alert-success]="isAllocatedSuccess" class="alert" *ngIf="isAllocated" >{{message}}</div>
<div class="row">
<div class="col text-right" >
<span><b>{{allocatedCab.AllocationStatusText}}</b></span>
</div>
</div>
<div class="row">
<div class="col-md-3">
<i class='fas fa-{{allocatedCab.CabType|lowercase}}' style='font-size:30px;'></i>
<br>
<b>{{allocatedCab.Occupance}}/{{allocatedCab.Capacity}}</b>
<p><b><span>{{allocatedCab.RouteType}}</span></b></p>
</div>
<!-- Add the cdkDropList attribute and drop list data here -->>
<div class="col-md-9 border-bottom" cdkDropList [cdkDropListData]="allocatedCab.AssignedEmployees" (cdkDropListDropped)="drop($event)">
<div class="row">
<p><b><span>{{allocatedCab.PickupPoint}} To {{allocatedCab.DropPoint}}</span></b></p>
</div>
<div class="row">
<p style="text-align: left"><b><span>{{allocatedCab.VendorName}} - {{allocatedCab.CabName}} - {{allocatedCab.RegNo}}</span></b></p>
</div>
<!-- Add cdkDrag attribute here -->>
<div class="row" *ngFor="let employee of allocatedCab.AssignedEmployees" cdkDrag>
<p style="text-align: left"><span class="fa fa-user"></span>
<a href="./admin#" (click)="open(content,allocatedCab,employee)">
{{employee.FirstName}} {{employee.LastName}} -
<small> {{employee.PickupDate | date: "hh:mm a"}} </small>
</a>
<i style="color:red; cursor: pointer;" class="fa fa-remove" (click)="openConfirmation(content1, employee)"></i></p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 pt-2 text-left ">
<span>{{allocatedCab.PickupDate | date: "dd/MM/yyyy hh:mm a"}}</span>
</div>
</div>
</div>
</div>
It is not mandatory to give cdkDropListGroup and cdkDropList in the same component. When the above code is rendered in the browser, the structure of the cdkDropListGroup and cdkDropList will be set as parent and child relation. So I hope, you may get what you require.

View more button inside a foreach loop only working for first item

I am looping through items on a foreach loop and every item comes with a "view more" tag. When I click it it should collapse and show more information about that item. My problem is that it is only collapsing for the first item on the loop. How do I make it work for every item that is returned?
#{
foreach (var news in Model)
{
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="single-item wow fadeInUp animated animated animated animated">
<div class="img-box">
<div class="img-holder">
<figure><img src="#news.file.Url" alt=""></figure>
</div>
</div>
<div class="news-content">
<h4>#news.Header</h4>
<div class="collapse" id="collapseExample">
#news.Description
</div>
<div class="show-more">
<a data-toggle="collapse" href="#collapseExample" data-parent="collapseExample" aria-expanded="true" aria-controls="collapseExample">Read More</a>
</div>
</div>
</div>
</div>
}
}
This is my loop
It's because you are rendering multiples elements with the same ID
Try this
var index = 1;
foreach(var news in Model){
[...]
<div class="collapse" id="collapse_#index">
#news.Description
</div>
<div class="show-more">
<a data-toggle="collapse" href="#collapse_#index" data-parent="collapseExample" aria-expanded="false" aria-controls="collapse_#index">Read More</a>
</div>
index++;
[...]
}
This way it will never repeat an ID element