how can my modal know index in row clicked reactjs - asp.net

I am a beginner in this language I've used php before.
So the table has a button and when I clicked the button it only read the first row it won't read the other rows, In php ive used the function attr so it will read the other clicked row and here at reactjs i don't know how please help
return <tr key={i} >
<td>{d.Employee_Name}</td>
<td>{d.Address}</td>
<td><center><button className ="btn btn-info" onClick={ this.props.onClick } data-toggle="modal" data-target="#UpdateEmployee">Update</button></center></td>
<td><center><button className ="btn btn-danger">Delete</button></center></td>
<div className="modal fade" id="UpdateEmployee" role="dialog">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" data-dismiss="modal">×</button>
<h4 className="modal-title">Update Employee</h4>
</div>
<div className="container">
<div className="modal-body">
<table>
<tbody>
<tr>
<td>Name</td>
<td> <input type="text"value={ d.Employee_Name} /> </td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" value={ d.Address} /> </td>
</tr>
</tbody>
</table>
</div>
</div>
<div className="modal-footer">
<botton className="btn btn-info"> Update Employee</botton>
<button type="button" className="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</tr>
}

To get the index of item clicked, you need to bind the index to onClick function for each element, like this:
<td>
<center>
<button ... onClick={() => this.props.onClick(i) }></button>
</center>
</td>
Note: replace ... by other properties you are using.
Whenever you click on any item, index i will get passed to this.props.onClick method, you can check that by using console.log in parent onClick function, like this:
onClick(index){
console.log(index); // it will print the index of item clicked
}

Related

How to insert multiple checkbox values into firebase using vue js

I've a form that contains a textarea and a table with a list of many members (from a collection named Members). Each table's contain two checboxes: one to mark the presence of the member and the second one to mark his payment. After clicking on the submit button I'd like to have in my firebase database something like this:
Meeting collection:
associationId,
textareaValue,
createdAd
Presence collection:
memberId,
meetingId,
present: true or false,
createAt
Payment collection:
memberId,
meetingId,
payment: true or false,
createAt
<form #submit.prevent="handleSubmitNewMeeting">
<!-- step one -->
<div class="card" v-if="showFormPart1">
<div class="card-header">
<h4>Entrer le sujet principal de la réunion</h4>
</div>
<div class="card-body">
<div class="form-group">
<textarea class="form-control" v-model="subjects" required rows="3"></textarea>
</div>
<p></p>
<div class="row">
<div class="col-sm-6">
<button #click="showForm=false" class="btn btn-danger" style="width: 100%">
Annuler
</button>
</div>
<div class="col-sm-6">
<button
type="button" class="btn btn-outline-secondary" #click="showFormPart2=true;
showFormPart1=false;">
Suivant
</button>
</div>
</div>
</div>
</div>
<p></p>
<!-- step two -->
<div class="card" v-if="showFormPart2">
<div v-if="members">
<div class="card-header">
<h4>Cocher les présences et payements</h4>
</div>
<div class="card-block p-0">
<table class="table table-bordered">
<thead class="">
<tr align="center">
<th scope="col">Nom</th>
<th scope="col">Prénom</th>
<th scope="col">Téléphone</th>
<th scope="col">Présence</th>
<th scope="col">Payment</th>
</tr>
</thead>
<tbody>
<tr v-for="member in members" :key="member.id" align="center">
<td>{{ member.memberFirstname }}</td>
<td>{{ member.memberLastname }}</td>
<td>{{ member.memberPhoneNumber }}</td>
<td>
<label class="switch">
<input type="checkbox" class="default" v-model="present">
<span class="slider round"></span>
</label>
</td>
<td>
<label class="switch">
<input type="checkbox" class="default" v-model="payment">
<span class="slider round"></span>
</label>
</td>
</tr>
</tbody>
</table>
<p></p>
<div class="row">
<div class="col-sm-6">
<button
type="button" class="btn btn-outline-secondary" #click="showFormPart2=false;
showFormPart1=true;">
Précédent
</button>
</div>
<div class="col-sm-6">
<button class="btn btn-secondary"> Valider </button>
</div>
</div>
</div>
</div>
</div>
<p></p>
</form>
How to do these with firebase using Vue Js please ? thanks !

Bootstrap modal inside the repeater ASP.Net

I am trying to show the information in a modal from a repeater. My sample code is fllowing.
<asp:Repeater ID="rptData" runat="server" OnItemDataBound="rptData_ItemDataBound">
<HeaderTemplate>
<table class="table table-striped">
<thead class="bg-secondary text-info">
<tr>
<th>Name</th>
<th>Type of Membership</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><button type="button" class="btn btn-link" id="memberNameList"
data-toggle="modal" data-target="#memberDetailsModal" runat="server"></button></td>
<td><asp:Literal id="typeOfMembershipList" runat="server"></asp:Literal></td>
</tr>
<div class="modal fade" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header border-bottom-0">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-title text-center">
<h3 class="font-weight-bold" id="memberName" runat="server">Member Name</h3>
<p class="font-weight-bold mb-0" id="typeOfMembership" runat="server">General Member</p>
</div>
</div>
</div>
</div>
</div>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
I can get all the data from the database in the table in multiple rows. But when I click the button from any row to pop up the modal, it's showing the information from the first row only in the modal. I am getting that, the modal is binding only the information from the first row. I am not sure why.
You can use the same modal for every row. Pass the values using HTML data-* attributes to the modal and then, you can use jQuery to get the data and modify the modal dynamically.
Bootstrap Docs: Varying modal content

table modal won't read any other rows reactjs

I have a problem it only reads the first row item, i dont know why it does that.. how can i use foreach loop for this... or any kind of code so it will work because it doesn't read any other row besides the first one im so confused because I haven't done reactjs before
PS: the data came from an api from asp.net...
you can check the image here
renderItem(d, i) {
debugger
return <tr key={i} >
<td> {d.Employee_ID} </td>
<td>{d.Employee_Name}</td>
<td>{d.Address}</td>
<td><center>
<button className ="btn btn-info" onClick={() => this.props.onClick(i) } data-toggle="modal" data-target="#UpdateEmployee">Edit</button></center></td>
<td><center><button className ="btn btn-danger">Delete</button></center></td>
<div className="modal fade" id="UpdateEmployee" role="dialog">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" data-dismiss="modal">×</button>
<h4 className="modal-title">Update Employee</h4>
</div>
<div className="container">
<div className="modal-body">
<table>
<tbody>
<tr>
<td>Name</td>
<td> <input type="text"value={d.Employee_Name} /> </td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" value={d.Address} /> </td>
</tr>
</tbody>
</table>
</div>
</div>
<div className="modal-footer">
<botton className="btn btn-info"> Update Employee</botton>
<button type="button" className="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</tr>
}
import React from 'react';
import 'whatwg-fetch';
export default class employee extends React.Component {
constructor() {
super();
this.state = { jsonReturnedValue: [] }
}
renderItem(d, i) {
debugger
return <tr key={i} >
<td> {d.Employee_ID} </td>
<td>{d.Employee_Name}</td>
<td>{d.Address }</td>
<td><center><button className ="btn btn-info" onClick={() => this.props.onClick(i) } data-toggle="modal" data-target="#UpdateEmployee">Edit</button></center></td>
<td><center><button className ="btn btn-danger">Delete</button></center></td>
<div className="modal fade" id="UpdateEmployee" role="dialog">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" data-dismiss="modal">×</button>
<h4 className="modal-title">Update Employee</h4>
</div>
<div className="container">
<div className="modal-body">
<table>
<tbody>
<tr>
<td>Name</td>
<td> <input type="text"value={d.Employee_Name} /> </td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" value={d.Address} /> </td>
</tr>
</tbody>
</table>
</div>
</div>
<div className="modal-footer">
<botton className="btn btn-info"> Update Employee</botton>
<button type="button" className="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</tr>
}
componentDidMount() {
fetch('http://localhost:5118/api/employeedetails/getemployeedetails')
.then((response) => {
return response.json()})
.then((json) => {
this.setState({jsonReturnedValue : json});
});
}
render() {
let {jsonReturnedValue} = this.state;
return(
<div>
<div className="container">
<h1> Listof Employees </h1>
<button className ='btn btn-warning right ' data-toggle="modal" data-target="#AddEmployee"> Add an Employee</button>
<table className= "table table-bordered">
<tbody>
<tr>
<th>ID</th>
<th>Name</th>
<th>Address</th>
<th>Update</th>
<th>Delete</th>
</tr>
{jsonReturnedValue.map((d,i) => this.renderItem(d,i))}
</tbody>
</table>
</div>
{/*Adding*/}
<div className="modal fade" id="AddEmployee" role="dialog">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" data-dismiss="modal">×</button>
<h4 className="modal-title">Add New Employee</h4>
</div>
<div className="container">
<div className="modal-body">
<table>
<tbody>
<tr>
<td>Name</td>
<td>
<input type="text"
name={this.props.Employee_Name}
className="EmployeeDetails"
value={this.props.value}
onChange={this.props.handleChange}/>
</td>
</tr>
<tr>
<td>Address</td>
<td>
<input type="text"
name={this.props.address}
className="EmployeeDetails"
value={this.props.value}
onChange={this.props.handleChange}/>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div className="modal-footer">
<botton className="btn btn-info" onClick = {this.save}> Add Employee</botton>
<button type="button" className="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
);
}
}`
I think something like this should work
import React from 'react';
import 'whatwg-fetch';
export default class employee extends React.Component {
let index = -1;
constructor() {
super();
this.state = { jsonReturnedValue: [] ,
name: '',
address: ''
}
}
renderItem(d, i) {
debugger
index++;
let name = d.Employee_Name;
let address = d.Address;
return <tr key={i} >
<td> {d.Employee_ID} </td>
<td>{d.Employee_Name}</td>
<td>{d.Address }</td>
<td><center><button className ="btn btn-info" onClick={() => this.props.onClick(i) } data-toggle="modal" data-target="#UpdateEmployee">Edit</button></center></td>
<td><center><button className ="btn btn-danger">Delete</button></center></td>
<div className="modal fade" id="UpdateEmployee" role="dialog">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" data-dismiss="modal">×</button>
<h4 className="modal-title">Update Employee</h4>
</div>
<div className="container">
<div className="modal-body">
<table>
<tbody>
<tr>
<td>Name</td>
<td> <input type="text"value={this.state.jsonReturnedValue[index].Employee_Name} /> </td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" value={this.state.jsonReturnedValue[index].Address} /> </td>
</tr>
</tbody>
</table>
</div>
</div>
<div className="modal-footer">
<botton className="btn btn-info"> Update Employee</botton>
<button type="button" className="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</tr>
}
componentDidMount() {
fetch('http://localhost:5118/api/employeedetails/getemployeedetails')
.then((response) => {
return response.json()})
.then((json) => {
this.setState({jsonReturnedValue : json});
});
}
render() {
let {jsonReturnedValue} = this.state;
return(
<div>
<div className="container">
<h1> Listof Employees </h1>
<button className ='btn btn-warning right ' data-toggle="modal" data-target="#AddEmployee"> Add an Employee</button>
<table className= "table table-bordered">
<tbody>
<tr>
<th>ID</th>
<th>Name</th>
<th>Address</th>
<th>Update</th>
<th>Delete</th>
</tr>
{jsonReturnedValue.map((d,i) => this.renderItem(d,i))}
</tbody>
</table>
</div>
{/*Adding*/}
<div className="modal fade" id="AddEmployee" role="dialog">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" data-dismiss="modal">×</button>
<h4 className="modal-title">Add New Employee</h4>
</div>
<div className="container">
<div className="modal-body">
<table>
<tbody>
<tr>
<td>Name</td>
<td>
<input type="text"
name={this.props.Employee_Name}
className="EmployeeDetails"
value={this.props.value}
onChange={this.props.handleChange}/>
</td>
</tr>
<tr>
<td>Address</td>
<td>
<input type="text"
name={this.props.address}
className="EmployeeDetails"
value={this.props.value}
onChange={this.props.handleChange}/>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div className="modal-footer">
<botton className="btn btn-info" onClick = {this.save}> Add Employee</botton>
<button type="button" className="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
);
}
}

<input/> Text input in Angular-UI accordion heading bootstrap inline edit

I am trying to insert an input in the header of Angular-UI's accordion, but the accordion messes up when the input is shown. I think it might be because I hide the actual heading text so the height of the header changes and the accordion messes up. Ideally, I would like to keep the height dynamic (responsive point-of-view), but a fixed height will do as well.
When the edit button is clicked, I want to show an input field in the header so the user can update the text (saving, or binding the value is not a concern.. just want to show the input field correctly).
I have a demo of what I am wanting using a table, and I would like to replicate that functionality into the accordion header.
<table class="table table-bordered table-striped table-hover">
<thead>
<tr id="th-row">
<th>Name</th>
<th class="col-xs-1">Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<span ng-show="!edit" ng-model="personName">John Smith</span>
<div ng-show="edit" class="col-xs-12">
<input type="text" ng-model="personName" ng-required="true" value="" class="form-control" placeholder="Person Name">
</div>
</td>
<td>
<button ng-show="!edit" class="btn btn-xs btn-primary" ng-click="edit = true">
<i class="glyphicon glyphicon-edit"></i>
</button>
<button ng-show="edit" class="btn btn-xs btn-danger" ng-click="edit = false">
<i class="glyphicon glyphicon-remove"></i>
</button>
</td>
</tr>
</tbody>
</table>
Now my accordion code:
<accordion-group>
<accordion-heading>
<span ng-show="!edit1" ng-model="headingName">Header with Button group</span>
<div ng-show="edit1" class="col-xs-12">
<input type="text" ng-model="headingName" ng-required="true" value="" class="form-control" placeholder="Heading Name">
</div>
<div class="pull-right">
<button ng-show="!edit1" class="btn btn-info btn-xs" ng-click="edit1 = true; $event.stopPropagation();"><i class="glyphicon glyphicon-edit"></i></button>
<button ng-show="edit1" class="btn btn-danger btn-xs" ng-click="edit1 = false; $event.stopPropagation();"><i class="glyphicon glyphicon-remove"></i></button>
</div>
</accordion-heading>
This is just some content to illustrate fancy headings.
</accordion-group>
Here is a Plunker Demo

Table inside form and both inside modal in Twitter Bootstrap does not display right, padding are missing

I have a situation here and perhaps solution is simple but I can't find a way out until now so I need some help.
I have this HTML code:
<div class="modal fade in" id="selectFabricante" tabindex="-1" role="dialog" aria-labelledby="selectFabricante" aria-hidden="false" data-backdrop="static" style="display: block; padding-right: 17px;"><div class="modal-backdrop fade in" style="height: 611px;"></div>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Cerrar</span></button>
<h4 class="modal-title">Seleccione uno o más fabricantes</h4>
</div>
<div class="modal-body">
<form id="fabForm" method="post" class="form-horizontal bv-form" novalidate="novalidate"><button type="submit" class="bv-hidden-submit" style="display: none; width: 0px; height: 0px;"></button>
<div class="form-group">
<div class="table-responsive">
<table class="table table-condensed">
<thead>
<tr>
<th><input type="checkbox" id="toggleChkSelFabricante" name="toggleChkSelFabricante"></th>
<th>Fabricante</th>
</tr>
</thead>
<tbody id="selFabricanteBody"><tr data-idproductosolicitud="1" data-id="1"><td><div class="checkbox"><label><input type="checkbox" name="fabLinkChoice[]" value="1"></label></div></td><td>Dist1</td><td>DR</td><td class="has_pais fabTd-1"><span id="14">México</span>, <span id="15">Nicaragua</span>, <span id="16">Panamá</span></td><td>1212212</td></tr><tr data-idproductosolicitud="1" data-id="1"><td><div class="checkbox"><label><input type="checkbox" name="fabLinkChoice[]" value="1"></label></div></td><td>Dist1</td><td>DR</td><td class="has_pais fabTd-1"><span id="14">México</span>, <span id="15">Nicaragua</span>, <span id="16">Panamá</span></td><td>1212212</td></tr></tbody>
</table>
</div>
</div>
<div>
<button type="button" class="btn btn-danger" data-dismiss="modal">Regresar</button>
<button type="submit" class="btn btn-primary" disabled="" id="btnAgregarSelFabricante"><i class="fa fa-save"></i> Agregar</button>
</div>
</form>
</div>
</div>
</div>
</div>
Which render as image below shows:
What can be wrong in that markup? I'm using latest version of Twitter Bootstrap. Any help? Advice?
Some clarifications:
I need the table inside the form because it's tabular data and semantic I think this is the right choice
I need the form because I'm using BootstrapValidator plugin and as says here in docs that the right markup, and I need to check at least one checkbox is checked before enable the submit button and allow send the form
Remove the element <div class="form-group"> and its end tag surrounding <div class="table-responsive">. That will fix the padding issue. You also have an issue with the checkbox class. If you remove the checkbox class from the <div> containing the checkbox it'll align properly.

Resources