<tr *ngFor="let upload of uploads; let i = index">
<td title="{{upload.documentName}}" class="first_col">{{upload.documentName}}</td>
<td>{{upload.inputDocumentPassword}}</td>
<td class="third_col">{{upload.documentFormat}}</td>
<td>{{upload.uploadTime|date }} <br><span class="time">{{upload.uploadTime|date :'shortTime' }}</span>
</td>
<td>{{upload.approvalStatus}}</td>
<td>
<div class="Action">
<i class="material-icons md-get_app" (click)="downloadOutput(upload)">get_app</i>
<i class="material-icons md-visibility">visibility</i>
<i class="material-icons md-picture_as_pdf" (click)="downloadpdf(upload)">picture_as_pdf</i>
<i class="material-icons md-delete"
(click)="fileToDelete(upload.documentName)" onclick="document.getElementById('id01').style.display='block'" >delete</i>
<div id="id01" class="w3-modal">
<div class="w3-container w3-teal">
<div class="Inner-tab">
<div class="tittle-box">
<label class="warning">WARNING</label>
</div>
<div class="are-you-sure-message">
<span>Are you sure you want to delete "{{documenttoDelete}}" file ?</span>
</div>
<div class="btn-tab">
<button class="cancle" onclick="document.getElementById('id01').style.display='none'">CANCEL</button>
<button class="yes" (click)="delete(upload)" (click)="reload()" >YES</button>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
When I'm trying to delete any row on the page, whichever row I click only 1st row is getting deleted!! I think there is some problem with the loop! Any help would be highly appreciated!
this is my .ts function
delete(userActivity) {
this.baseService.delete(environment.restPath+'file', userActivity.id).subscribe(
(data) => {
this.getPageItems();
})
console.log(event);
}
getPageItems():void{
this.baseService.getData(environment.restPath+'file/list/page/'+ this.pageNum+ '?thisUserOnly=true').subscribe(
(data) => {
this.total = data.result.totalCount;
this.userActivityList = [];
this.userActivityList = data.result.list;
})
}
call it like :-
<button class="yes" (click)="delete(i);reload()" >YES</button>
In Typescript :-
delete(userActivity) {
this.baseService.delete(environment.restPath+'file', userActivity.id).subscribe(
(data) => {
this.getPageItems();
this.uploads = this.uploads.filter((upload)=> upload.id !== userActivity.id);
})
console.log(event);
}
Related
I trying to make search bar that search in different column I have an property table where I want to search the data with different things like I want to search data with price range an also I want to search data with area range. I make this in asp.net core mvc. I want to make search look like that https://www.zameen.com/
My View:
#model IEnumerable<eHouse.Models.RentModel>
<form>
<div class="wrap">
<div class="search">
<input type="text" class="searchTerm" style="width: 700px; color:#000000; text-align: left;" placeholder="Search Houses" onclick="filterfunction()">
<button type="submit" class="searchButton" >
<i class="fa fa-search"></i>
</button>
</div>
<div id="filter">
<select>
<option value="Kanal">Kanal</option>
<option value="Marla">Marla</option>
<option value="Square Feet">Square Feet</option>
<option value="Square Meter">Square Meter</option>
<option value="Square Yards">Square Yards</option>
</select>
<input type="text" placeholder="area" />
<input type="text" placeholder="price" />
</div>
</div>
</form>
Kindly also tell me that how can I bind data with this to display in this div.
<div class="property_information" >
#foreach (var item in Model)
{
<div class="home-info">
<span id="houseid">
</span>
<a href="#" class="home-images">
<img src="#item.pic1" />
</a>
<div class="home-data">
<div class="home-name">
<p>#item.tittle</p>
</div>
<div class="price">
<p>#item.price</p>
</div>
<div class="features">
<span>
#item.bedroom
</span>
<span>
#item.bathroom
</span>
<span>
2
</span>
</div>
<div class="desc">
#item.descrip
</div>
<div class="contact-save">
<a href="#" class="phone_number" id="favorite" onclick="Fav(this)" data-id="#item.id" >
<i class="fas fa-heart" style=" color: white;"></i>
</a>
<div class="popup" onclick="myFunction()">
<a href="tel:+928754756478" class="phone_number" onclick="call()">
</a>
</div>
<div class="popupmsg" onclick="myFunctionmsg()">
<a href="#" class="phone_number open_message" onclick="msg()">
</a>
</div>
<a href="#" class="phone_number" onclick="del(this)" data-id="#item.id">
<i class="fas fa-trash-alt" style=" color: white;"></i>
</a>
</div>
</div>
</div>
}
</div>
My Controller:
public IActionResult Rent(int PageNumber = 1)
{
var data = rdb.GetDataHouse();
var datas = rdb.GetDataHouse();
ViewBag.Data = datas.ToList().Take(6);
ViewBag.Totalpages = Math.Ceiling(data.Count()/6.0);
data = data.Skip((PageNumber - 1) * 6).Take(6).ToList();
return View(data);
}
try using tables and import jquery data tables library
<table id="table">
<thead>
<tr>
<th>col 1</th>
<th>col 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>data 1</td>
<td>data 2</td>
</tr>
</tbody>
</table>
<script>
$('#table').DataTable({
processing: true,
serverSide: true,
...rest
})
</script>
I would like to user firstly select the filters which is given in search bar dropdown like AREA or PRICE RANGE etc. I do not know how to put filter and also I want to display those search in on same page. I create this in ASP.NET Core MVC using ADO.NET for database using the SQL queries.
My view:
#model IEnumerable<eHouse.Models.RentModel>
<div class="navbar-left-section">
<form>
<div class="wrap">
<div class="search">
<input type="text" class="searchTerm" style="width: 700px; color:#000000; text-align: left;" placeholder="Search Houses">
<button type="submit" class="searchButton" >
<i class="fa fa-search"></i>
</button>
</div>
</div>
</form>
</div>
Here is how I display the data:
<div class="property_information" >
#foreach (var item in Model)
{
<div class="home-info">
<span id="houseid">
</span>
<a href="#" class="home-images">
<img src="#item.pic1" />
</a>
<div class="home-data">
<div class="home-name">
<p>#item.tittle</p>
</div>
<div class="price">
<p>#item.price</p>
</div>
<div class="features">
<span>
#item.bedroom
</span>
<span>
#item.bathroom
</span>
<span>
2
</span>
</div>
<div class="desc">
#item.descrip
</div>
<div class="contact-save">
<a href="#" class="phone_number" id="favorite" onclick="Fav(this)" data-id="#item.id" >
<i class="fas fa-heart" style=" color: white;"></i>
</a>
<div class="popup" onclick="myFunction()">
<a href="tel:+928754756478" class="phone_number" onclick="call()">
</a>
</div>
<div class="popupmsg" onclick="myFunctionmsg()">
<a href="#" class="phone_number open_message" onclick="msg()">
</a>
</div>
<a href="#" class="phone_number" onclick="del(this)" data-id="#item.id">
<i class="fas fa-trash-alt" style=" color: white;"></i>
</a>
</div>
</div>
</div>
}
</div>
Here I want to just display the results of search.
My controller:
public IActionResult Rent(int PageNumber = 1)
{
var data = rdb.GetDataHouse();
var datas = rdb.GetDataHouse();
ViewBag.Data = datas.ToList().Take(6);
ViewBag.Totalpages = Math.Ceiling(data.Count()/6.0);
data = data.Skip((PageNumber - 1) * 6).Take(6).ToList();
return View(data);
}
I tried as below:
In View
#model SearchBarModel
<form asp-action="SearchBarTest">
<a>Filter:</a>
<input list="options" asp-for="FilterProperty" />
<datalist id="options">
<option value="Price"></option>
<option value="Location"></option>
</datalist>
<br />
<a>Range</a>
<input list="range" asp-for="Range"/>
<datalist id="range">
</datalist>
<br />
<input type="submit" value="Submit" />
</form>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script>
$("#FilterProperty").change(function () {
var val = $("#FilterProperty").val()
$("#range option").remove()
if (val == "Price")
{
$("#range").append('<option value="10~20"></option>');
$("#range").append('<option value="20~30"></option>');
}
if (val == "Location")
{
$("#range").append('<option value="China"></option>');
$("#range").append('<option value="American"></option>');
}
});
</script>
Model:
public class SearchBarModel
{
public string FilterProperty { get; set; }
public string Range { get; set; }
}
Controller:
[HttpPost]
public IActionResult SearchBarTest(string FilterProperty,string Range)
{
return View();
}
Result:
This question expands on my problem which got partially solved here. I have two components, ApplicationOverview.js and ApplicationModal.jsx and I want to dynamically add div panels to the ApplicationOverview.js Component from the Modal. In the Modal I have two input fields and I can add an image, which will be displayed on the div after I clicked on the 'Add' button. This is what the Modal looks like and this is what I am trying to achieve with n number of panels. (Note that the first 3 panels are hard coded)
So far, I can add a single div panel to my page, but whenever I try to add another one, it just changes the text of the panel that I just added. I am currently just toggling the visibility of that single div I am adding with a boolean (as you can see on the bottom of ApplicationOverview.js), but I can't figure out how I'd add multiple divs from my Modal to the page. Also, when I close the Modal but type something into the input fields, the text on the added div will still change without clicking on 'Add' beforehand.
ApplicationModal.jsx:
import React from "react";
var name = "";
var comment = "";
var filename = "";
const ApplicationModal = ({
setOpen,
setState,
setStateComment,
setFile,
file,
setBool,
}) => {
React.useEffect(() => {
function handleEscapeKey(event) {
if (event.code === "Escape") {
setOpen(false);
}
}
document.addEventListener("keydown", handleEscapeKey);
return () => document.removeEventListener("keydown", handleEscapeKey);
});
const handleComment = (e) => {
setStateComment(e.target.value);
};
const handleChange = (e) => {
setState(e.target.value);
};
const addNewApplication = () => {
setBool(true);
setOpen(false);
};
function openDialog() {
document.getElementById("inputUpload").click();
}
function loadFile(e) {
console.log(e.target.files);
setFile(URL.createObjectURL(e.target.files[0]));
}
document.addEventListener("click", function (e) {});
return (
<React.Fragment>
<div className="modalDark" style={{ paddingRight: "250px" }}>
<div class="modal-dialog">
<div class="modal-content" style={{ width: "800px" }}>
<div class="modal-close">
<div class="module-button" style={{ left: "750px" }}>
<button
class="btn btn-link "
onClick={() => setOpen(false)}
></button>
<div class="button-animation"></div>
<div class="button-content new">
<i class="icon icon-dc_close"></i>
</div>
</div>
</div>
<div class="modal-header">
<h3>Add new Application</h3>
</div>
<div class="modal-body">
<div
class="module-input form-group has-placeholder"
data-plugin="moduleInput"
style={{ bottom: "60px", width: "350px" }}
>
<label for="demo-default">Customer Name</label>
<div class="input-animation-wrapper">
<input
type="text"
id="demo-default"
class="form-control "
maxLength="42"
placeholder="[Application Name]"
onChange={(e) => handleChange(e)}
/>
<div class="input-animation"></div>
</div>
</div>
<div
class="module-textarea form-group floating-label has-placeholder"
data-plugin="moduleInput"
style={{ bottom: "60px" }}
>
<label for="demo-3">Customer Short text</label>
<div class="input-animation-wrapper" style={{ width: "350px" }}>
<textarea
id="demo-3"
class="form-control"
rows="9"
placeholder="Short description of Customer; max. 280 characters"
maxLength={180}
onChange={(e) => handleComment(e)}
style={{ width: "350px" }}
></textarea>
<div class="label-area"></div>
<div class="input-animation"></div>
</div>
</div>
<img
class="image"
alt="Customer Logo"
id="logo"
src={file}
style={{
left: "420px",
bottom: "280px",
position: "absolute",
height: "250px",
}}
/>
<div
class="module-button"
style={{
left: "500px",
bottom: "200px",
position: "absolute",
zIndex: "1",
}}
>
<button
type="file"
class="btn btn-light"
onClick={() => openDialog()}
id="fileUpload"
>
<input
type="file"
hidden={true}
accept="image/*"
id="inputUpload"
onChange={(e) => loadFile(e)}
></input>
</button>
<div class="button-animation"> </div>
<div class="button-content">
<span class="content-text">Upload Logo</span>
</div>
</div>
<div
class="module-button"
style={{ bottom: "50px", width: "100px", textAlign: "center" }}
>
<button
type="button"
class="btn btn-secondary btn"
onClick={() => addNewApplication()}
id="adding"
></button>
<div class="button-animation"></div>
<div class="button-content">
<span class="content-text">Add</span>
</div>
</div>
</div>
</div>
</div>
</div>
</React.Fragment>
);
};
export default ApplicationModal;
export { name, comment, filename };
ApplicationOverview.js:
import React from "react";
import "../Overview.css";
import ApplicationModal from "../components/ApplicationModal.jsx";
var id = 0;
const ApplicationOverview = () => {
const [open, setOpen] = React.useState(false);
const [state, setState] = React.useState("");
const [stateComment, setStateComment] = React.useState("");
const [file, setFile] = React.useState("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Placeholder_view_vector.svg/681px-Placeholder_view_vector.svg.png");
const [bool, setBool] = React.useState(false);
function addID()
{
id++;
console.log(id)
return id;
}
return (
<div id="wrapper">
{open && <ApplicationModal setOpen={setOpen} setState={setState} file={file} setBool={setBool} setFile={setFile} setStateComment={setStateComment} />}
<div class="component-headline">
<h4 style={{ color: "gray", display: "inline" }}>
Application overview
</h4>
<div
class="module-button"
style={{
backgroundColor: "rgb(18,205,212,255)",
borderRadius: "12px",
marginLeft: "1032px",
}}
onClick={() => setOpen(true)}
>
<button type="button" class="btn btn-secondary"></button>
<div class="button-animation"></div>
<div
class="button-content"
style={{
backgroundColor: "rgb(18,205,212,255)",
borderRadius: "12px",
}}
>
<span class="content-text" style={{ color: "black" }}>
Add Application
</span>
</div>
</div>
</div>
<hr style={{ marginTop: "-20px" }} />
<div class="center-content" id="center">
<div class="overview-box">
<img
class="image"
src="https://st.depositphotos.com/1968353/2535/i/600/depositphotos_25357041-stock-photo-close-up-of-machine-gears.jpg"
alt="car"
/>
<div class="box-content">
<h3 class="overview-h3">Press</h3>
<p class="overview-p">This Application is used for maintenance</p>
<h3 class="overview-h3-second">Connected Products</h3>
<h1 class="overview-h1-second">
?/?
<p class="overview-p-second">Online</p>
</h1>
<div class="module-button" id="configure">
<button type="button" class="btn btn-secondary"></button>
<div class="button-animation"></div>
<div class="button-content">
<span class="content-text">Configure</span>
</div>
</div>
</div>
</div>
<div class="overview-box">
<img
class="image"
src="https://st.depositphotos.com/1968353/2535/i/600/depositphotos_25357041-stock-photo-close-up-of-machine-gears.jpg"
alt="car"
/>
<div class="box-content">
<h3 class="overview-h3">Tooling Machine</h3>
<p class="overview-p">
This Application is used for drilling records
</p>
<h3 class="overview-h3-second">Connected Products</h3>
<h1 class="overview-h1-second">
?/?
<p class="overview-p-second">Online</p>
</h1>
<div class="module-button" id="configure">
<button type="button" class="btn btn-secondary"></button>
<div class="button-animation"></div>
<div class="button-content">
<span class="content-text">Configure</span>
</div>
</div>
</div>
</div>
<div class="overview-box">
<img
class="image"
src="https://st.depositphotos.com/1968353/2535/i/600/depositphotos_25357041-stock-photo-close-up-of-machine-gears.jpg"
alt="car"
/>
<div class="box-content">
<h3 class="overview-h3">Storing Unit</h3>
<p class="overview-p">
This Application is used for store parameters
</p>
<h3 class="overview-h3-second">Connected Products</h3>
<h1 class="overview-h1-second">
?/?
<p class="overview-p-second">Online</p>
</h1>
<div class="module-button" id="configure">
<button type="button" class="btn btn-secondary"></button>
<div class="button-animation"></div>
<div class="button-content">
<span class="content-text">Configure</span>
</div>
</div>
</div>
</div>
{(stateComment || state) && bool && <div class='overview-box' id={addID()}> <img class='image' src={file} alt='car'/> <div class='box-content'><h3 class='overview-h3' id='new-headline'>{state}</h3> <p class='overview-p'>{stateComment}</p><h3 class='overview-h3-second'>Connected Products</h3><h1 class='overview-h1-second'> ?/? <p class='overview-p-second'>Online</p> </h1> <div class='module-button' id='configure'> <button type='button' class='btn btn-secondary'></button> <div class='button-animation'></div> <div class='button-content'> <span class='content-text'>Configure</span> </div> </div> </div> </div> }
</div>
</div>
);
};
export default ApplicationOverview;
So if I understand your problem is that you have a modal and when you fill the modal and send add it will add the text and images to ApplicationOverview. I think you want to be able to do that several times. You want your users to be able to complete the modal again and again so it keep adding at the bottom of the ApplicationOverview.
So you need your ApplicationModal to have its own state.
const [modalState, setModalState] = useState("");
const [modalCommentState, setCommentModalState] = useState("");
const [modalFile, setModalFile] = useState("");
so your handler function should be
const handleComment = (e) => {
setCommentModalState(e.target.value);
};
const handleChange = (e) => {
setModalState(e.target.value);
};
function loadFile(e) {
setModalFile(URL.createObjectURL(e.target.files[0]));
}
Your submit function
const addNewApplication = () => {
setOpen(false);
setStates( oldArray => [...oldArray, {
state:modalState,
stateComment:modalCommentState,
file: modalFile } ]);
};
in the ApplicationOverview.js
const [states, setStates] = useState([]);
in your HTML section you loop through the state with a map
{ states.map((state)=> {
return (
<div class='overview-box' id={addID()}>
<img class='image' src={state.file} alt='car'/>
<div class='box-content'>
<h3 class='overview-h3' id='new-headline'>{state.state}</h3>
<p class='overview-p'>{state.stateComment}</p>
<h3 class='overview-h3-second'>Connected Products</h3>
<h1 class='overview-h1-second'> ?/? <p class='overview-p-second'>Online</p></h1>
<div class='module-button' id='configure'>
<button type='button' class='btn btn-secondary'></button>
<div class='button-animation'></div>
<div class='button-content'>
<span class='content-text'>Configure</span>
</div>
</div>
</div>
</div>
})}
So everytime the user submit the modal it will get added to the array of states and it will be display in the ApplicationOverview
I'm fairly new to using TypeScript, React and Bootstrap modals in general, however I'm pretty confident that I have avoided the most common mistakes like using the same id and data-bs-target in multiple places.
Basically I have a dynamic list of accordions. Each accordion has a body which (in this case) contains a list of restaurants. I have a modal which allows the user to edit this list of restaurants when clicking on the 'Edit' button. As you can see in the code below, the value of the button's data-bs-target has the state constant deckId which changes accordingly when clicking on any of the accordions. Same goes for the id of each modal.
Excuse the bad markup below. Also ignore it if there are is a bracket or a tag too much or too little. I edited out a bunch of broken code so I might've accidentally deleted something unintentionally with that.
The accordions:
const DeckList = (list: any[]) => {
var numberToWords = require('number-to-words');
return (
<div className="accordion" id="accordionPanelsCloseEachother">
{/* <div id="myGroup"> */}
<div className="accordion-group">
{list
.sort((a, b) => a.deckLevel > b.deckLevel ? 1 : -1)
.map((d: DeckModel) => {
return (
<div className="accordion-item" key={d.id}
>
<h2 className="accordion-header" >
<button
onClick={() => setDeckId(d.id)}
className="accordion-button collapsed"
type="button"
data-bs-toggle="collapse"
data-bs-target={"#" + numberToWords.toWords(d.deckLevel)}
aria-expanded="false"
aria-controls={numberToWords.toWords(d.deckLevel)}
>
Level {d.deckLevel}
</button>
</h2>
<div id={numberToWords.toWords(d.deckLevel)} className="accordion-collapse collapse" data-bs-parent="#accordionPanelsCloseEachother">
<div className="accordion-body">
<div className="row">
<div className="col-sm-4">
<div className="card">
<div className="card-body">
<h5 className="card-title">{intl.formatMessage({ id: 'RESTAURANTS' })}</h5>
{restDeckListNEW.filter(f => f.deckId === d.id).map((r: RestaurantDeckModel) => {
return (
<li key={r.restaurantId}>{r.restaurantName}</li>
)
})}
</div>
<div className="position-absolute bottom-0 end-0 p-7">
<EditRestaurantFunction
intl={intl}
shipId={shipId}
list={list}
deckId={deckId}
filteredRestaurants={filteredRestaurants}
GET_DECK_URL={GET_DECK_URL}
GET_RESTAURANTDECK_URL={GET_RESTAURANTDECK_URL}
setStatusCode={setStatusCode}
statusCode={statusCode}
GET_SHIP_URL={GET_SHIP_URL}
setReloadValue={setReloadValue}
restDeckListNEW={restDeckListNEW}
checkedRestaurantIdList={checkedRestaurantIdList}
setCheckedRestaurantIdList={setCheckedRestaurantIdList}
unCheckedRestaurantIdList={unCheckedRestaurantIdList}
setUnCheckedRestaurantIdList={setUnCheckedRestaurantIdList} />
</div>
</div>
</div>
<div className="col-sm-4">
<div className="card">
<div className="card-body">
<h5 className="card-title">{intl.formatMessage({ id: 'FACILITIES' })}</h5>
{facilityListNEW.filter(f => f.deckLevel === d.deckLevel || f.optXtrDeckLevel === d.deckLevel).map((t: FacilitiesModel) =>
<li key={facilityListNEW.filter(f => f.deckLevel === d.deckLevel).indexOf(t)}>{t.name}</li>
)}
</div>
<div className="position-absolute bottom-0 end-0 p-7">
<button
type='button'
className='btn btn-warning'
data-bs-toggle='modal'
data-bs-target='#kt_modal_edit2'
onClick={() => getDeck(d.id)}
>
{intl.formatMessage({ id: 'EDIT' })}
</button>
</div>
</div>
</div>
<div className="col-sm-4">
<div className="card">
<div className="card-body">
<h5 className="card-title">{intl.formatMessage({ id: 'CABIN_CATEGORY' })}</h5>
{cabinDeckListNEW.filter(f => f.deckId === d.id).map((c: CabinDeckModel) => {
return (
<li key={c.cabinToDeckId}>{c.category + ' - ' + c.description + ' - ' + c.cabinType}</li>
)
})}
</div>
<div className="position-absolute bottom-0 end-0 p-7">
<button
type='button'
className='btn btn-warning'
data-bs-toggle='modal'
data-bs-target='#kt_modal_edit3'
onClick={() => getDeck(d.id)}
>
{intl.formatMessage({ id: 'EDIT' })}
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
)
})}
</div>
</div>
)
}
The modal component w/ button a.k.a. <EditRestaurantFunction />:
<div className="col-md-auto">
<button
type='button'
className='btn btn-warning'
data-bs-toggle='modal'
data-bs-target={'#editRestaurants' + deckId}
onClick={ifHasThenChecked}
>
{intl.formatMessage({ id: 'EDIT' })}
</button>
</div>
<div className="modal fade" tabIndex={-1} id={'editRestaurants' + deckId}>
<div className="modal-dialog modal-dialog-centered mw-900px">
<div className="modal-content">
<div className="modal-header">
<h5 className="modal-title">{intl.formatMessage({ id: 'EDIT_RESTAURANT_TO_DECK' })}</h5>
<button
type="button"
className="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
id='closeButtonEditRestaurantDeck'
>
</button>
</div>
<div className="modal-body py-lg-10 px-lg-10">
<div
ref={stepperRef}
className='stepper stepper-pills stepper-column d-flex flex-column flex-xl-row flex-row-fluid'
id='kt_modal_create_app_stepper'
>
<div className='d-flex justify-content-center justify-content-xl-start flex-row-auto w-100 w-xl-300px'>
<div className='stepper-nav ps-lg-10'>
<div className='stepper-item current' data-kt-stepper-element='nav'>
<div className='stepper-line w-40px'></div>
<div className='stepper-icon w-40px h-40px'>
<i className='stepper-check fas fa-check'></i>
<span className='stepper-number'>1</span>
</div>
<div className='stepper-label'>
<h3 className='stepper-title'>{intl.formatMessage({ id: 'EDIT_RESTAURANT_LIST' })}</h3>
<div className='stepper-desc'>{intl.formatMessage({ id: 'SELECT_RESTAURANTS' })}</div>
</div>
</div>
</div>
</div>
<div className='flex-row-fluid py-lg-5 px-lg-15'>
<Formik
validationSchema={currentSchema}
initialValues={initValues}
onSubmit={submitStep}
>
{({ errors, status, touched }) => (
<Form className='form' noValidate id='kt_modal_create_cabin_benefits_form'>
<div className='current' data-kt-stepper-element='content'>
<div className='w-100'>
<div className='fv-row mb-10'>
<label className='d-flex align-items-center fs-5 fw-bold mb-2'>
<span>{intl.formatMessage({ id: 'RESTAURANTS' })}</span>
<i
className='fas fa-exclamation-circle ms-2 fs-7'
data-bs-toggle='tooltip'
title={intl.formatMessage({ id: 'SELECT_ANY_NUMBER_RESTAURANTS' })}
></i>
</label>
{filteredRestaurants
.map((r: RestaurantDeckModel) => (
<div className="form-check mt-5" key={r.restaurantId} >
<input className="form-check-input" type="checkbox" value="" id={r.restaurantName}
onClick={() => checkRestaurants(r.restaurantId, r.restaurantName)}
/>
<label className="form-check-label" htmlFor="flexCheckDefault">
{r.restaurantName} - {r.restaurantId}
</label>
</div>
))}
</div>
</div>
</div>
<div>
<button
type='submit'
className='btn btn-lg btn-primary me-3'>
<span className='indicator-label'>
{intl.formatMessage({ id: "AUTH.GENERAL.SUBMIT_BUTTON" })}
</span>
</button>
</div>
</Form>
)}
</Formik>
</div>
</div>
</div>
</div>
</div>
</div>
So far I'm able to open the modal for the first accordion, but when I click on any other accordion and then on the 'Edit' button which triggers the modal to appear, it simply doesn't and also doesn't give any error message in the console. What am I doing wrong?
This is my second question ever on stackoverflow, so do let me know if I'm missing anything important in my question!
UPDATE: I figured out via this questions that my modal only shows up if the first accordion is expanded as well besides any other accordion that I might open. If I close the first accordion and open any other accordion, the modal will not appear. In the solution of the referenced question they use jQuery, which is something I'd like to avoid as much as possible.
Any idea how I can fix this issue using my technologies?
I did this in the past year and it works just fine. Until recently I encounter this problem which I don't know what caused it.
Here I'm trying to pass supplierID from a (1)form through (2)ajax javascript and return the (3)data from AdminController to a (4)div in the same view
(1)form:-
<?php $form = ActiveForm::begin([
'id'=>'chatform'
]);?>
<div class="box-body">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>No</th>
<th>Supplier</th>
<th>Option(s)</th>
</tr>
</thead>
<tbody>
<?php
for($x = 0; $x < count($supplierChatInfoListTable); $x++){ ?>
<tr>
<td>
<?=$x+1?>
<div class="form-group">
<input type="hidden" name="supplierID" id="supplierID" class="form-control"
value="<?=$supplierChatInfoListTable[$x]['supplierID']?>" style="width: 50px">
</div>
</td>
<td >
<h4><?=$supplierChatInfoListTable[$x]['supplierFirstname']?></h4>
</td>
<td>
<button type="button" class="btn btn-primary btnchat"><i class="fa fa-edit"></i></button>
</td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<th>No</th>
<th>Supplier</th>
<th>Option(s)</th>
</tr>
</tfoot>
</table>
</div>
<?php ActiveForm::end();?>
and here is my (2)javascript running in the same view:-
<?php
$urproudcode= Url::to(['admin/chatinfo2pass']);
$this->registerJs("
$(function(){
$('.btnchat').click(function(){
var supplierID = $('#supplierID').val();
$.ajax({
'url':'".$urproudcode."',
'data':{supplierID:supplierID},
'method':'POST',
beforeSend: function (xhr) {
$.blockUI({
message: 'Processing...',
css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: .5,
color: '#fff'
}
});
},
'success':function(data){
$('.chatmessages').html('Success');
if(data == 'false'){
$.unblockUI();
$('.chatmessages').html('Data False');
}else{
$.unblockUI();
$('.chatmessages').html(data);
}
},
error: function (xhr, ajaxOptions, thrownError) {
$.unblockUI();
$('.chatmessages').html('Failed');
console.log(data);
}
});
});
});
");
?>
(3)div with class=chatmessages in the same view
<div class="col-md-8 chatmessages">
</div>
(4)actionChatinfo2pass in AdminController
public function actionChatinfo2pass()
{
$postData = \Yii::$app->request->post('supplierID');
$supplierID = intval($postData);
// fetch all supplier for chat
$supplierChatInfoListTable = SupplierProfile::find()
->select(['supplier_profileID AS supplierID','supplier_profile.first_name AS supplierFirstname',
'supplier_profile.middle_name AS supplierMiddlename', 'supplier_profile.last_name AS
supplierLastname', 'login_profile.login_profileID AS loginID', 'status_login.status_loginID AS
statusLoginID', 'status_login.description AS statusLogindesc'])
->leftJoin('login_profile', 'login_profile.login_profileID = supplier_profile.login_profile_ID')
->leftJoin('status_login', 'status_login.status_loginID = login_profile.status_login_ID')
//->where(['=', 'status_login.description', $activeSupplier])
->orderBy(['supplier_profile.supplier_profileID' => SORT_ASC])
->asArray()
->all();
$dataSend['supplierChatInfoListTable'] = $supplierChatInfoListTable;
$this->layout = 'admin/main';
$html= $this->renderAjax('#app/views/admin/displaychatmessage.php',$dataSend);
echo $html;
}
But it return the 'same' supplierID for both supplier as show below:
and browser console give me this error?(updated):-
btw, this is the content of displaychatmessage.php (I just try to display supllierID and their name)
<!-- DIRECT CHAT WARNING -->
<div class="box box-warning direct-chat direct-chat-warning">
<div class="box-header with-border">
<h3 class="box-title">Direct Chat</h3>
<div class="box-tools pull-right">
<span data-toggle="tooltip" title="3 New Messages" class="badge bg-yellow">3</span>
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-toggle="tooltip" title="Contacts" data-widget="chat-pane-toggle">
<i class="fa fa-comments"></i></button>
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div>
<!-- /.box-header -->
<div class="box-body">
<!-- Conversations are loaded here -->
<div class="direct-chat-messages">
<!-- Message. Default to the left -->
<div class="direct-chat-msg">
<div class="direct-chat-info clearfix">
<?php for($z = 0; $z < count($supplierChatInfoListTable); $z++){?>
<span class="direct-chat-name pull-left">Supplier ID: <?=$supplierChatInfoListTable[$z]['supplierID']?>, <?=$supplierChatInfoListTable[$z]['supplierFirstname']?> <?=$supplierChatInfoListTable[$z]['supplierMiddlename']?> <?=$supplierChatInfoListTable[$z]['supplierLastname']?></span>
<?php }?>
<span class="direct-chat-timestamp pull-right">23 Jan 2:00 pm</span>
</div>
<!-- /.direct-chat-info -->
<img class="direct-chat-img" src="dist/img/user1-128x128.jpg" alt="Message User Image"><!-- /.direct-chat-img -->
<div class="direct-chat-text">
Is this template really for free? That's unbelievable!
</div>
<!-- /.direct-chat-text -->
</div>
<!-- /.direct-chat-msg -->
<!-- Message to the right -->
<div class="direct-chat-msg right">
<div class="direct-chat-info clearfix">
<span class="direct-chat-name pull-right">Sarah Bullock</span>
<span class="direct-chat-timestamp pull-left">23 Jan 2:05 pm</span>
</div>
<!-- /.direct-chat-info -->
<img class="direct-chat-img" src="dist/img/user3-128x128.jpg" alt="Message User Image"><!-- /.direct-chat-img -->
<div class="direct-chat-text">
You better believe it!
</div>
<!-- /.direct-chat-text -->
</div>
<!-- /.direct-chat-msg -->
</div>
<!--/.direct-chat-messages-->
<!-- Contacts are loaded here -->
<div class="direct-chat-contacts">
<ul class="contacts-list">
<li>
<a href="#">
<img class="contacts-list-img" src="dist/img/user1-128x128.jpg" alt="User Image">
<div class="contacts-list-info">
<span class="contacts-list-name">
Count Dracula
<small class="contacts-list-date pull-right">2/28/2015</small>
</span>
<span class="contacts-list-msg">How have you been? I was...</span>
</div>
<!-- /.contacts-list-info -->
</a>
</li>
<!-- End Contact Item -->
</ul>
<!-- /.contatcts-list -->
</div>
<!-- /.direct-chat-pane -->
</div>
<!-- /.box-body -->
<div class="box-footer">
<form action="#" method="post">
<div class="input-group">
<input type="text" name="message" placeholder="Type Message ..." class="form-control">
<span class="input-group-btn">
<button type="submit" class="btn btn-warning btn-flat">Send</button>
</span>
</div>
</form>
</div>
<!-- /.box-footer-->
</div>
<!--/.direct-chat -->
Can you help me with this? I don't know where it went wrong.
As you have mentioned you are getting same supplierID on clicking both supplier. This problem is caused because in your js code you are getting supplierID by id of the input i.e '#supplierID', and according to your html code the input elements of both of the suppliers have same value in their id attribute i.e 'supplierID', because of that every time js will get value from first input element with id attribute value 'supplierID'. So you need to make some changes in your html and js code. As there is separate edit button for each supplier so instead of using input to store supplierID value you can store it in a data attribute in the edit button. So your updated html code would become
<?php $form = ActiveForm::begin([
'id'=>'chatform'
]);?>
<div class="box-body">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>No</th>
<th>Supplier</th>
<th>Option(s)</th>
</tr>
</thead>
<tbody>
<?php
for($x = 0; $x < count($supplierChatInfoListTable); $x++){
$supID = $supplierChatInfoListTable[$x]['supplierID']; ?>
<tr>
<td>
<?=$x+1?>
<div class="form-group">
<input type="hidden" name="<?='supplierID'.$supID?>" id="<?='supplierID'.$supID?>" class="form-control"
value="<?=$supID?>" style="width: 50px">
</div>
</td>
<td >
<h4><?=$supplierChatInfoListTable[$x]['supplierFirstname']?></h4>
</td>
<td>
<button type="button" class="btn btn-primary btnchat" data-supplierID="<?=$supID?>"><i class="fa fa-edit"></i></button>
</td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<th>No</th>
<th>Supplier</th>
<th>Option(s)</th>
</tr>
</tfoot>
</table>
</div>
<?php ActiveForm::end();?>
And then get the supplierID of clicked supplier from data attribute of button in js. So your js code would become
<?php
$urproudcode= Url::to(['admin/chatinfo2pass']);
$this->registerJs("
$(function(){
$('.btnchat').click(function(){
var supplierID = $(this).attr('data-supplierID');
$.ajax({
'url':'".$urproudcode."',
'data':{supplierID:supplierID},
'method':'POST',
beforeSend: function (xhr) {
$.blockUI({
message: 'Processing...',
css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: .5,
color: '#fff'
}
});
},
'success':function(data){
$('.chatmessages').html('Success');
if(data == 'false'){
$.unblockUI();
$('.chatmessages').html('Data False');
}else{
$.unblockUI();
$('.chatmessages').html(data);
}
},
error: function (xhr, ajaxOptions, thrownError) {
$.unblockUI();
$('.chatmessages').html('Failed');
console.log(data);
}
});
});
});
");
?>
I hope your problem will be solved.