how to get data from one of the table rows - html

I tried to make a crud application, and stuck in the data update section, I don't know how to get data values ​​from one row of the table and bring them up in the input form to be edited.
This is my code
#model Web.Cifo.Cms.Models.AccountModel
<h2>Account</h2>
<hr />
<div class="row m-1">
<div class="col-md-push-4 mt-2 mr-5 ml-4">
<form method="post" asp-controller="home" asp-action="account">
<label for="uname">Username</label>
<input type="text" id="uname" asp-for="username" required="required" class="form-control" style="width:250px">
<label class="mt-2" for="pass">Password</label>
<input type="password" asp-for="password" required="required" id="pass" class="form-control" style="width:250px">
<label class="mt-2" for="name">Name</label>
<input type="text" id="name" asp-for="nama" required="required" class="form-control" style="width:250px">
<label class="mt-2" for="contact">Phone Number</label>
<input type="number" id="contact" asp-for="hp" required="required" class="form-control" style="width:250px">
<label class="mt-2" for="email">Email</label>
<input type="email" id="email" asp-for="email" required="required" class="form-control" style="width:250px">
<label class="mt-2" for="url">Profil Image Url</label>
<input type="text" id="url" asp-for="profil_image" required="required" class="form-control" style="width:250px">
<div class="row mt-2 pl-3">
<button type="submit" class="btn btn-dark">Add</button>
</div>
</form>
</div>
<div class="col-md-pull-8 m-1">
<h6>Select Table For Edit Or Delete</h6>
<!-- Editable table -->
<div class="card" style="overflow-x:scroll; overflow-y:scroll; height:50rem; width:70rem">
<h3 class="card-header text-center font-weight-bold text-uppercase py-4">Account</h3>
<div class="card-body mr-2">
<div id="table" class="table-editable">
<table class="table table-bordered table-responsive-md table-striped text-center" style="table-layout:fixed">
<thead>
<tr>
<th class="text-center" style="width:15rem">Action</th>
<th class="text-center" style="width:10rem">User Name</th>
<th class="text-center" style="width:10rem">Password</th>
<th class="text-center" style="width:10rem">Name</th>
<th class="text-center" style="width:15rem">Phone</th>
<th class="text-center" style="width:10rem">Email</th>
<th class="text-center" style="width:15rem">Profile Image Url</th>
</tr>
</thead>
<tbody>
#foreach (var acc in ViewBag.account)
{
<tr>
<td>
<a class="btn btn-danger btn-rounded btn-sm my-0" asp-controller="home" asp-action="deleteaccount" asp-route-id="#acc.username" onclick="return confirm ('Are You Sure ?')">Remove</a>
<a id="edtbtn" class="btn btn-danger btn-rounded btn-sm my-0">Edit</a>
</td>
<td class="pt-3-half">#acc.username</td>
<td class="pt-3-half">#acc.password</td>
<td class="pt-3-half">#acc.nama</td>
<td class="pt-3-half">#acc.hp</td>
<td class="pt-3-half">#acc.email</td>
<td class="pt-3-half">#acc.profil_image</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
<!-- Default input with help text-->
</div>
</div>
So, what I want is, when I press this edit button
<a id="edtbtn" class="btn btn-danger btn-rounded btn-sm my-0">Edit</a>
data from the selected row can be displayed here.
label for="uname">Username</label>
<input type="text" id="uname" asp-for="username" required="required" class="form-control" style="width:250px">
<label class="mt-2" for="pass">Password</label>
<input type="password" asp-for="password" required="required" id="pass" class="form-control" style="width:250px">
<label class="mt-2" for="name">Name</label>
<input type="text" id="name" asp-for="nama" required="required" class="form-control" style="width:250px">
<label class="mt-2" for="contact">Phone Number</label>
<input type="number" id="contact" asp-for="hp" required="required" class="form-control" style="width:250px">
<label class="mt-2" for="email">Email</label>
<input type="email" id="email" asp-for="email" required="required" class="form-control" style="width:250px">
<label class="mt-2" for="url">Profil Image Url</label>
<input type="text" id="url" asp-for="profil_image" required="required" class="form-control" style="width:250px">
I am totally new to this, please explain in a way that is easy to understand. thank you

Please refer to the following code snippet to dynamically populate tags with selected row data.
Html code
<a id="edtbtn" class="btn btn-danger btn-rounded btn-sm my-0" onclick="return edit_func(this);">Edit</a>
JavaScript code
<script>
//pass current row to function
function edit_func(row) {
//console.log($($(row).parent().siblings()[0]).text());
//get expected data from selected row
var username = $($(row).parent().siblings()[0]).text();
var password = $($(row).parent().siblings()[1]).text();
var nama = $($(row).parent().siblings()[2]).text();
var hp = $($(row).parent().siblings()[3]).text();
var email = $($(row).parent().siblings()[4]).text();
var profil_image = $($(row).parent().siblings()[5]).text();
//populate input(s) with selected row data
$("#uname").val(username);
$("#pass").val(password);
$("#name").val(nama);
$("#contact").val(hp);
$("#email").val(email);
$("#url").val(profil_image);
return false;
}
</script>
In account action
public IActionResult Account(AccountModel account)
{
//code logic here
//insert new record or update the existing one
//...
return View(model);
}

Related

how to pass the value of an object to another object, already as a variable in Angular?

My class Inbound looks like down bellow.
export class Inbound {
constructor(
public id: number,
public incomingType: string,
public quantity: number,
public location: string,
public arrived: Date,
public bin: Bin,
public truck: Truck,
public supplier: Supplier
) {
HTML ->
<tr>
<th>ID</th>
<th>Incoming Type</th>
<th>Quantity</th>
<th>Location</th>
<th>Arrived</th>
<th>Bin</th>
<th>Truck</th>
<th>Supplier</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let inbound of inbounds">
<td><span>{{inbound.id}}</span></td>
<td><span>{{inbound.incomingType}}</span></td>
<td><span>{{inbound.quantity}}</span></td>
<td><span>{{inbound.location}}</span></td>
<td><span>{{inbound.arrived}}</span></td>
<td><span>{{inbound.bin.name}}</span></td>
<td><span>{{inbound.truck.regNumber}}</span></td>
<td><span>{{inbound.supplier.name}}</span></td>
<td>
I have problems with passing these 3 last variables because.
My code in Java works, i have checked on Postman.
Frontend in Angular meets some lack of knowledge by my side.
Method createNewInbound is not visible fron Angular.
<ng-template #content let-modal>
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">New Inbound</h4>
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form #f="ngForm" (ngSubmit)="onSubmit(f)" novalidate>
<div class="form-group">
<label for="incomingType">Incoming Type</label>
<div class="input-group">
<input id="incomingType" name="incomingType" class="form-control" ngModel>
</div>
</div>
<div class="form-group">
<label for="quantity">Quantity</label>
<div class="input-group">
<input id="quantity" name="quantity" class="form-control" ngModel>
</div>
</div>
<div class="form-group">
<label for="location">Location</label>
<div class="input-group">
<input id="location" name="location" class="form-control" ngModel>
</div>
</div>
<div class="form-group">
<label for="arrived">Arrived</label>
<div class="input-group">
<input id="arrived" name="arrived" class="form-control" ngModel>
</div>
***[FROM HERE !!!]
**</div>
<div class="form-group">
<label for="bin.name">Bin Name</label>
<div class="input-group">
<input id="bin.name" name="bin.name" class="form-control" ngModel>
</div>
</div>
<div class="form-group">
<label for="truck.regNumber">Truck Reg Number</label>
<div class="input-group">
<input id="truck.regNumber" name="truck.regNumber" class="form-control" ngModel>
</div>
</div>
<div class="form-group">
<label for="supplier.name">Supplier Name</label>
<div class="input-group">
<input id="supplier.name" name="supplier.name" class="form-control" ngModel>
</div>
[TILL HERE!!!]*****
</div>
<div class="border text-center">
<button data-dismiss="modal" class="btn btn-info">Submit</button>
</div>
</form>
</div>
I realize that it might looks like Butter butter and might be time-consuming.
If somobody is willing to help me it might be great New Year surpise for me.
Here is my repo -> https://github.com/sroko1/Shipping-Bins.git.
Have a good day & year.
I
You would need to make use of ngModelGroup directive. Below is the code snippet:
<div class="form-group" ngModelGroup="bin"> <!-- Added ngModelGroup="bin" -->
<label for="bin">Bin Name</label>
<div class="input-group">
<input id="bin" name="name" class="form-control" ngModel> <!-- Updated name attribute value -->
</div>
</div>
<div class="form-group" ngModelGroup="truck"> <!-- Added ngModelGroup="truck" -->
<label for="truck.regNumber">Truck Reg Number</label>
<div class="input-group">
<input id="truck.regNumber" name="regNumber" class="form-control" ngModel> <!-- Updated name attribute value -->
</div>
</div>
<div class="form-group" ngModelGroup="supplier"> <!-- Added ngModelGroup="supplier" -->
<label for="supplier.name">Supplier Name</label>
<div class="input-group">
<input id="supplier.name" name="name" class="form-control" ngModel> <!-- Updated name attribute value -->
</div>
</div>
This will help you to get expected f.value within onSubmit()

Old Data After Form submit on laravel

<div class="card-body">
<form action="" >
<div class="row">
<div class="col-5">
<label for="">From Date</label>
<input type="date" class="form-control" name="from" id="from" value="{{old('from')}}" required>
</div>
<div class="col-5">
<label for="">To Date</label>
<input type="date" class="form-control" name="to" id="to" value="{{old('to')}}" required>
</div>
<div class="col2 pt-4 mt-2">
<input type="submit" class="btn btn-success" value="search">
</div>
</div>
</form>
</div>
I want my from data after submission. i am using get request to search data and refresh the page with new data with from date fields with old search data
As I understood you want to show new data on your page while the from and to are from your previous request ?
Then why are you not returning the to and from with new data.
<input type="date"
class="form-control"
name="from"
id="from"
value= #if($from) "{{$from}}" #endif required>
<input type="date"
class="form-control"
name="to"
id="to"
value= #if($to) "{{$to}}" #endif required>
from controller return data that you want to return after applying the filters with the to and from

Laravel Model Not Saving

Model is saving but all is null values excepts dates
There is not thrown error.
$fillable are directly copied from the field at my migrations.
I cant find why is that it is saving null values on the database
Here is my Code
My Model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Disbursement_Information extends Model
{
use SoftDeletes;
protected $table = 'disbursement';
protected $fillable = [
'cv_number',
'payee_id',
'amount',
'check_number',
'release_date',
'first_collection_date',
'last_collection_date',
'maturity_date'
];
protected $dates = [
'created_at',
'updated_at',
'deleted_at'
];
}
My Controller
public function postDisbursement(Request $request, $id){
$loans = new Disbursement_Information;
$input = $request->all();
$loans->save($input);
}
HTML FORM
<div id="step-1">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header"> List of All Clients</h1>
<h2>Total Clients: <b>3</b></h2>
<div class="row">
</div>
</div>
</div>
<!-- /.col-lg-12 -->
</div>
<hr>
<div class="col-lg-6 col-md-6">
<div class="form-group">
<label for="cv_number"> Check Voucher # </label>
<input type="text" class="form-control" name="cv_number" id="cv_number" required>
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="form-group">
<label for="check_number"> Check # </label>
<input type="text" class="form-control" name="check_number" id="check_number" required>
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="form-group">
<label for="first_collection_date"> First Payment </label>
<input type="date" class="form-control" name="first_collection_date" id="first_collection_date" required>
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="form-group">
<label for="last_collection_date"> Last Payment </label>
<input type="date" class="form-control" name="last_collection_date" id="last_collection_date" required>
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="form-group">
<label for="maturity_date"> Maturity Date </label>
<input type="date" class="form-control" name="maturity_date" id="maturity_date" required>
</div>
</div>
<div class="col-lg-6 col-md-6">
<div class="form-group">
<label for="payee_name"> Payee </label>
<input type="text" class="form-control" name="payee_name" id="payee_name" readonly>
<input type="hidden" class="form-control" name="payee_id" id="payee_id" required>
</div>
</div>
<input type="hidden" name="_token" value="JvvXJbloRAzQnj4oz4ve6Z8OLLia270Fs6utSO5a">
<table class="table table-striped">
<thead>
<th>Name</th>
<th style="">Loan Amount</th>
<th style="text-align:center">Action</th>
</thead>
<tbody>
<tr >
<td class="">
Morgado, Ashbee, Allego
</td>
<td>
<input type="number" min="2000" max="99000" name="loan_amount[1]" class="form-control loan-amount">
</td>
<td style="text-align:center">
<div class="radio">
<label><input type="checkbox" class="reloan" name="reloan[1]" p_id = "1 "p_name="Morgado, Ashbee, Allego" target-rdb="rdb1"> Not re-loaning/loaning </label>
<label id="rdb1"><input type="radio" class="rdbPayee" name="payee_id" value="1" p_name="Morgado, Ashbee, Allego">Mark As Payee</label>
<button type="button" class="btn btn-sm btn-default loan-summary"><i class="fa fa-info-circle fa-5" aria-hidden="true"></i></button>
</div>
</td>
</tr>
<tr >
<td class="">
Melton, Barbara, None
</td>
<td>
<input type="number" min="2000" max="99000" name="loan_amount[2]" class="form-control loan-amount">
</td>
<td style="text-align:center">
<div class="radio">
<label><input type="checkbox" class="reloan" name="reloan[2]" p_id = "2 "p_name="Melton, Barbara, None" target-rdb="rdb2"> Not re-loaning/loaning </label>
<label id="rdb2"><input type="radio" class="rdbPayee" name="payee_id" value="2" p_name="Melton, Barbara, None">Mark As Payee</label>
<button type="button" class="btn btn-sm btn-default loan-summary"><i class="fa fa-info-circle fa-5" aria-hidden="true"></i></button>
</div>
</td>
</tr>
<tr >
<td class="">
Bonyton, Ester, Jaxis
</td>
<td>
<input type="number" min="2000" max="99000" name="loan_amount[3]" class="form-control loan-amount">
</td>
<td style="text-align:center">
<div class="radio">
<label><input type="checkbox" class="reloan" name="reloan[3]" p_id = "3 "p_name="Bonyton, Ester, Jaxis" target-rdb="rdb3"> Not re-loaning/loaning </label>
<label id="rdb3"><input type="radio" class="rdbPayee" name="payee_id" value="3" p_name="Bonyton, Ester, Jaxis">Mark As Payee</label>
<button type="button" class="btn btn-sm btn-default loan-summary"><i class="fa fa-info-circle fa-5" aria-hidden="true"></i></button>
</div>
</td>
</tr>
</tbody>
</table>
<div class="modal-footer">
<button type="submit" class="btn btn-success"> Submit </button>
</div>
</div>

html table with bootstrap textfield

Hi I need to add textfield in html table using bootstrap, but when using the bootstrap class in html table cell teh textfield is too small.
In the following code example the problem is in textfield id="Winvnetv".
<table class="table table-bordered table-striped">
<tr>
<form id="formSuppliestrn" method="post" class="form-horizontal" >
<td>
<input type="text" name="Wsupplyid" id="Wsupplyid" >
</td>
<td><input type="text" name="Wsupplydesc" id="Wsupplydesc"></td>
<td><input type="text" name="Wquantity" id="Wquantity"></td>
<td>
<div class="form-group">
<label class="col-xs-3 control-label">Ποσό τιμολογίου</label>
<div class="col-xs-3">
<div class="input-group">
<span class="input-group-addon">€</span>
<input type="text" class="form-control" name="Winvnetv" id="Winvnetv"/>
</div>
</div>
</div>
</td>
<td>
<input type="text" name="Wtotv" id="Wtotv">
</td>
<td> <button type="submit" class="btn btn-sm btn-primary" id="trnadd">
<span class="glyphicon glyphicon-plus-sign"></span>
</button>
</td>
</form>
</tr>
</tbody>
</table>
any idea?
You can add the input-lg or input-sm class to the textbox. It will increase its size.
<input type="text" class="form-control input-lg" name="Winvnetv" id="Winvnetv"/>

div tags doesn't remain fixed if page is zoomed in or zoomed out

I have a bootstrap template html code:
<section id="main-content">
<section class="wrapper">
<h3><i class="fa fa-angle-right"></i>Create New Space Marine Chapter</h3>
<div class="row mt" >
<div class="col-md-12" >
<div class="content-panel" >
<form class="form-inline" action="add.php" method="POST">
<div class="row">
<div class="form-group col-lg-5" style='float:initial;width:680px;height:240px'>
<div class="form-group col-lg-4">
<label for="id">ID:</label>
<input class="form-control" type="text" name="ID" required="required" />
</div>
<div class="form-group col-lg-4">
<label for="name">Name:</label>
<input class="form-control" type="text" name="Name" required="required"/>
</div>
<div class="form-group col-lg-4">
<label for="founding">Founding:</label>
<input class="form-control" type="text" name="Founding" required="required"/>
</div>
<div class="form-group col-lg-4">
<label for="successor_of">Successor Of:</label>
<input class="form-control" type="text" name="Successor_Of" required="required"/>
</div>
<div class="form-group col-lg-4">
<label for="successor_chapters">Successor Chapters:</label>
<input class="form-control" type="text" name="Successor_Chapters" required="required"/>
</div>
<div class="form-group col-lg-4">
<label for="number">Number:</label>
<input class="form-control" type="text" name="Number" required="required"/>
</div>
<div class="form-group col-lg-4">
<label for="primarch">Primarch:</label>
<input class="form-control" type="text" name="Primarch" required="required"/>
</div>
<div class="form-group col-lg-4">
<label for="chapter_master">Chapter Master:</label>
<input class="form-control" type="text" name="Chapter_Master" required="required"/>
</div>
<div class="form-group col-lg-4">
<label for="homeworld">Homeworld:</label>
<input class="form-control" type="text" name="Homeworld" required="required"/>
</div>
<div class="form-group col-lg-4">
<label for="allegiance">Allegiance:</label>
<input class="form-control" type="text" name="Allegiance" required="required"/>
</div>
<div class="form-group col-lg-4">
<label for="colors">Colors:</label>
<input class="form-control" type="text" name="Colors" required="required"/>
</div>
</div>
</div>
<br>
<div class="form-group col-md-1 ">
<button onclick="showAddRecordDiv()" type="submit" class="btn btn-default">Create</button>
</div>
</form>
<form action="javascript:getLastRecord();" method="GET">
<div class="form-group col-md-2">
<button type="submit" class="btn btn-default">Show Last Created</button>
</div>
</form>
<form action="javascript:getAllRecords();" method="GET">
<div class="form-group col-lg-1">
<button type="submit" class="btn btn-default">Show All</button>
</div>
</form>
<table id="advanced-table" class="table table-striped table-advance table-hover">
<thead>
<tr>
<th style="text-align:center" width="50">ID</th>
<th style="text-align:center" width="100">Name</th>
<th style="text-align:center" >Founding</th>
<th style="text-align:center" width="150">Successor Of</th>
<th style="text-align:center" width="200" >Successor Chapters</th>
<th style="text-align:center" >Number</th>
<th style="text-align:center" >Primarch</th>
<th style="text-align:center" width="200" >Chapter Master</th>
<th style="text-align:center" >Homeworld</th>
<th style="text-align:center" >Allegiance</th>
<th style="text-align:center" >Colors</th>
<th style="text-align:center" width="100" >Input Date</th>
<th style="text-align:center" >Delete</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div id="alert-div" class="alert alert-danger" hidden="hidden">
<strong>RECORD DELETED</strong>
</div>
<div id="add-record-div" class="alert alert-success" hidden="hidden">
<strong>CHAPTER CREATED</strong>
</div>
</div><!-- /content-panel -->
</div><!-- /col-md-12 -->
</div><!-- /row -->
</section><! --/wrapper -->
</section><!-- /MAIN CONTENT -->
My problem is when I zoom in or out the page, all divs' positions changes and page's layout brakes. Here is some examples:
Page with size of 33%:
Page with size of 100%:
Page with size of 175%:
I searched over internet and saw that I must set divs' sizes fixed/static. I did something with float and width-height but it didn't help. What can I do for not to break page's layout?