I have a table wherein I've iterated 3 FA-icons inside Button tag using *ngFor, like the image shown here.
I have given the 3 buttons separate IDs(viz. 1,2&3) to note which button is clicked. The buttons are Add, Edit and Delete. Although I'm sending it's ID through (click) event to the component. The function is not able to retrieve the ID every time the button is clicked. It retrieves the ID after random multiple clicks and not each time the button is clicked. I don't understand why it's behaving like this.
HTML:
<tbody>
<tr *ngFor="let ABC of XYZ">
<td>{{ABC.Records}}}</td>
<td>
<button id="1" (click)="fun($event)"><fa-icon [icon]="plussquare"></fa-icon></button>
<button id="2" (click)="fun($event)" ><fa-icon [icon]="editfa"></fa-icon></button>
<button id="3" (click)="fun($event)" ><fa-icon [icon]="trashfa"></fa-icon></button>
</td>
</tr>
</tbody>
.TS:
fun($event:any){
console.log($event.target.id)
}
All add buttons should have id 1, edit buttons should have id 2 and 3 for delete buttons.
Do you not just need 3 methods ?
funEdit($event:any, yourVar){
console.log($event.target.id)
}
funAdd($event:any, yourVar){
console.log($event.target.id)
}
funDelete($event:any, yourVar){
console.log($event.target.id)
}
That you will use like it :
<button (click)="funAdd($event,ABC)"><fa-icon [icon]="plussquare"></fa-icon></button>
<button (click)="funEdit($event,ABC)" ><fa-icon [icon]="editfa"></fa-icon></button>
<button (click)="funDelete($event,ABC)" ><fa-icon [icon]="trashfa"></fa-icon></button>
And passing your ABC var in second params to know the line
Related
Here is where my button is located:
<body>
<h3 class="paragraph">Remove the duplicates in 2 Javascript arrays (found in readme), add the results to an array and output the list of distinct names in an unordered list below this paragraph when <button type="button" onclick="show" id="btnID" class="javabutton">
this link</button> is clicked. If the operation has been completed already, notify the user that this has already been done.</h3>
And here is the unordered list I want my button to display:
<ul class="javalist" id="javalist">
<li>Matt Johnson</li>
<li>Bart Paden</li>
<li>Ryan Doss</li>
<li>Jared Malcolm</li>
<li>Jordan Heigle</li>
<li>Tyler Viles</li>
</ul>
</body>
How do I make the button toggle between hiding/showing the list?
I don't know how you made show(), but you have to use brackets in the onclick attribute like this:
function show(){
var list = document.getElementById("javalist");
if(list.style.display != "none") list.style.display = "none";
else list.style.display = "block";
}
<body>
<h3 class="paragraph">Remove the duplicates in 2 Javascript arrays (found in readme), add the results to an array and output the list of distinct names in an unordered list below this paragraph when <button type="button" onclick="show()" id="btnID" class="javabutton" >
this link</button> is clicked. If the operation has been completed already, notify the user that this has already been done.</h3>
<ul class="javalist" id="javalist" style="display: none;">
<li>Matt Johnson</li>
<li>Bart Paden</li>
<li>Ryan Doss</li>
<li>Jared Malcolm</li>
<li>Jordan Heigle</li>
<li>Tyler Viles</li>
</ul>
</body>
If the user clicks in the edit button, it should displays the data in a form inside a modal, however for some reason it needs to click one user, and then another one to show the data. I even tried putting the id from the object in a "h1" tag and it's displaying it correctly in the first click, not sure why.
Here is the first click, as you can see in the console it shows the correct data
And you can even see that the "h1" tag contains the id from the object, but it doesn't show the data in the input tags.
Here is after clicking in another user
It shows all the data correctly after changing to another.
Here are the files that i used.
component.html, this is how i show the data
<input *ngIf="add_modify" type="email" id="name" class="form-control" mdbInput value="{{clicked_user.full_name}}" [(ngModel)]="user.full_name" name="full_name">
<input *ngIf="!add_modify" type="email" id="name" class="form-control" mdbInput [(ngModel)]="user.full_name" name="full_name">
<label for="name">Nombres</label>
<h1 *ngIf="add_modify">{{clicked_user._id}}</h1>
<a (click)="frame.show(); showUserInfo(el)" data-toggle="modal" data-target="#add_user" class="mr-3">
<tr mdbTableCol *ngFor="let el of elements">
<td>{{el.full_name}}</td>
<td>{{el.email}}</td>
<td>{{el.work_station}}</td>
<td>
<a (click)="frame.show(); showUserInfo(el)" data-toggle="modal" data target="#add_user" class="mr-3">
<mdb-icon fas icon="user-edit" class="text-info"></mdb-icon>
</a>
<a (click)="deleteUser()">
<mdb-icon fas icon="user-times" class="text-danger"></mdb-icon>
</a>
</td>
</tr>
Component.ts, this is how i get the data for the clicked user
showUserInfo(user) {
this.clicked_user = user;
console.log(this.clicked_user);
this.add_modify = true;
console.log(this.add_modify);
}
Any sugestions?
I never created the new User(), so it wasn't saving the data correctly, i just made a blank User() at the constructor of the component and it worked just fine.
I want to disable last from clicking because that column contains the delete action button.
I do not want to use JS or JQuery, I was wondering if it is posible to disable it inside HTML tag code.
This is not a duplicated question because most similar questions include the use of JS or Jquery which I don't want to use.
<tr onclick="location.href = '#Url.Action("DetallePedido", "Pedidos", new { id = pedido.Id })'" class="bg-warning">
<td>#pedido.Id</td>
<td>#pedido.FechaPedido</td>
<td>#pedido.Cliente.Nombres</td>
<td>#pedido.Region</td>
<td>#pedido.ContactoPrincipal</td>
<td>#pedido.Telefonoc</td>
<td>#pedido.SubTotal</td>
<td>#pedido.Total</td>
<td>#pedido.FechaEntrega</td>
<td>#pedido.Direccion</td>
<td>
#if (pedido.User != null)
{
#pedido.User.Name
} else
{
#pedido.Vendedor
}
</td>
<td class="text-center"><a class="btn btn-danger btn-xs text-white" onclick="cancelarPedido(#pedido.Id)"><i class="fas fa-trash-alt"></i></a></td>
</tr>
You could set CSS style="pointer-events: none;" to the delete link. See: https://css-tricks.com/almanac/properties/p/pointer-events/
It's not very nice solution though, you'd better just change the onclick attribute to return: false;.
I have used bootstrap-vue to create buttons inside a table. Requirement was to get the data of the button that was clicked. But since I used a for loop, even though i click on any of the 3 buttons (number is based on for loop), the data is getting rendered for all the 3 buttons on clickon any of the 3 buttons. I tried using "collapse-{{index}}" so that the index value might change. But if use this I am getting module error.
<b-tbody>
<b-tr v-for="(_,index) in gradableItems" :key="index">
<b-td>
<div>
<b-button
:class="visible ? null : 'collapsed'"
:aria-expanded="visible ? 'true' : 'false'"
aria-controls="collapse-4"
#click="fetchGIChildren({gradableItemId:gradableItems[index].id+'',userID:'701709', giIndex: index}), visible = !visible"
></b-button>
</div>
{{gradableItems[index].id+" "+gradableItems[index].name}}
<table>
<b-collapse id="collapse-4" v-model="visible" class="mt-2">
<tr v-for="(_,childIndex) in gradableItems[index].children" :key="childIndex">
<td>{{gradableItems[index].children[childIndex].status +' '+ gradableItems[index].children[childIndex].name}}</td>
</tr>
</b-collapse>
</table>
I have a table in "clients.html" that contains clients data,when I clic on one of those clients then the "create Document" I want to send the data of this clients to the new page "Doc.html",this is my code:
clients.html
<div class="btn-group" style="
right: 5px;
" ng-repeat="post in posts">
<div class="btn btn-icon">
<a ui-sref="app.deviscl({customerID:post.id})" data-toggle="tooltip" title="create Doc"><img src="img\facturejj.png"
class="m-b-xs w-xs"> </a>
</div></div>
this is the routing:
.state('app.deviscl', {
url: '/devis/ajout/:customerID',
templateUrl: 'tpl/deviscl.html',
controller: 'editController'
})
but in the clients.html the button create Doc appears many times,If I try to remove ng-repeat from the div of the button I can't get any result
thanks a lot for help
Basicly with this code you are creating a button for every post in posts. I am guessing you want 1 button, but somehow that 1 button knows which post in posts is selected?
In that case you can create a form with a select dropdown, then they pick a 'post in posts' from the select and then submit the form, which links them to the create doc page with the right data?
UPDATE
Example as requested:
<form>
<table>
<tr>
<td>
<select ng-model="postId" ng-options="post.id as post for post in posts"></select>
</td>
</tr>
<tr>
<td><input type="submit" ng-click="createDoc(postId) value="save" /></td>
</tr>
</table>
</form>
Ofcourse you can alter this simple form to be applicable for your own app. e.g add css or change some names etc.
and then in your controller:
$scope.createDoc = function(postId) {
app.deviscl({customerID:postId});
}
and your routing remains the same.