how to disable input when the value is empty laravel livewire - laravel

i am using livewire , laravel 7. Below is the code. How to make sure the input is readonly when the value is empty?
<div class="form-row">
#foreach($serviceOrder as $o)
<div class="col-md-5 mb-3">
<label class="form-control-label" >Service {{ $loop->iteration }} </label>
<input type="text" wire:model="serviceOrder.{{ $loop->index }}.serv.serviceName" class="form-control " readonly>
</div>
<input type="hidden" wire:model="serviceOrder.{{ $loop->index }}.serv.servicePrice" class="form-control col-sm-1 mb-3" readonly>
<div class="col-md-3 mb-3">
<label class="form-control-label" >Weight/Size</label>
<input type="text" name="" value="" wire:model="serviceOrder.{{ $loop->index }}.weightsize" class="form-control">
</div>
<div class="col-md-3 mb-3">
<label class="form-control-label" >Quantity*opt</label>
<input type="text" name="" value="" wire:model="serviceOrder.{{ $loop->index }}.quantity" class="form-control" #if(!$quantity) readonly #endif >
</div>
#endforeach
</div>
the one i am focusing is this part
<div class="col-md-3 mb-3">
<label class="form-control-label" >Quantity*opt</label>
<input type="text" name="" value="" wire:model="serviceOrder.{{ $loop->index }}.quantity" class="form-control" #if(!$quantity) readonly #endif >
</div>
for the input that has no value, should be " ", it is a nullable variable for quantity

try adding this check in the element:
<input type="text" wire:model="serviceOrder.{{ $loop->index }}.quantity" class="form-control" #if(!$serviceOrder[$loop->index]['quantity']) readonly #endif>

Related

PHP Laravel Post action

I have a form page for users informations update but my post function isn't working.I have defined a post method in the blade page and I show the page as a formaction post.This is my code;
#extends('layouts.admin-master')
#section('content')
<form action="post">
<div class="form-row">
<div class="form-group">
<label for="inputAddress2">Ad Soyad</label>
<input type="text" class="form-control" id="inputAddress2" name="name" value="{{ Auth::user()->name }}">
</div>
<br><br>
<div class="form-group">
<label for="inputAddress2">Şirket</label>
<input type="text" class="form-control" id="inputAddress2" name="company">
</div>
</div>
<div class="form-group">
<label for="inputAddress">Email</label>
<input type="text" class="form-control" id="inputAddress" name="email" value="{{ Auth::user()->email }}">
</div>
<div class="form-group">
<label for="inputAddress2">Telefon</label>
<input type="text" class="form-control" id="inputAddress2" name="phone">
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputState">Üyelik Tipi</label>
<select id="inputState" class="form-control">
<option selected>Seçenekler</option>
<option>Bronz Üyelik</option>
<option>Silver Üyelik</option>
<option>Gold Üyelik</option>
</select>
</div>
<div class="form-group col-md-2">
<label class="radio-container m-r-55">Tedarikçi
<input type="radio" checked="checked" name="secim" value="tedarikci">
<span class="checkmark"></span>
</label>
`enter code here` <label class="radio-container">Alıcı
<input type="radio" name="secim" value="alici">
<span class="checkmark"></span>
</label>
</div>
</div>
<form action="{{route('form.add')}}" method="post" enctype="multipart/form-data">
<button type="submit" class="btn btn-primary">Kaydet</button>
</form>
</form>
#endsection
try this:
#extends('layouts.admin-master')
#section('content')
<form action="{{route('form.add')}}" method="post" enctype="multipart/form-data">
<div class="form-row">
<div class="form-group">
<label for="inputAddress2">Ad Soyad</label>
<input type="text" class="form-control" id="inputAddress2" name="name" value="{{ Auth::user()->name }}">
</div>
<br><br>
<div class="form-group">
<label for="inputAddress2">Şirket</label>
<input type="text" class="form-control" id="inputAddress2" name="company">
</div>
</div>
<div class="form-group">
<label for="inputAddress">Email</label>
<input type="text" class="form-control" id="inputAddress" name="email" value="{{ Auth::user()->email }}">
</div>
<div class="form-group">
<label for="inputAddress2">Telefon</label>
<input type="text" class="form-control" id="inputAddress2" name="phone">
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputState">Üyelik Tipi</label>
<select id="inputState" class="form-control">
<option selected>Seçenekler</option>
<option>Bronz Üyelik</option>
<option>Silver Üyelik</option>
<option>Gold Üyelik</option>
</select>
</div>
<div class="form-group col-md-2">
<label class="radio-container m-r-55">Tedarikçi
<input type="radio" checked="checked" name="secim" value="tedarikci">
<span class="checkmark"></span>
</label>
`enter code here` <label class="radio-container">Alıcı
<input type="radio" name="secim" value="alici">
<span class="checkmark"></span>
</label>
</div>
</div>
<button type="submit" class="btn btn-primary">Kaydet</button>
</form>
put this line in your form and it should work :
{{csrf_field()}}
and make sure that your route address is correct too
u can add #csrf above the button

How to show a new column after using select2 in laravel?

I have a form and using select2 for filter. I want to show new column by using this select2.
I don't know its possible or not but i want to do this . using jquery or something, can someone reference to me about this? its my form for my input
<form class="form-prevent-multiple-submits" data-toggle="validator" action="{{route('update_sarpras_aduan'),'test'}} " method="post">
#csrf
{{method_field('patch')}}
<div class="form-group">
<label class="control-label" for="title">Nama Unit:</label>
<input type="text" name="nama_unit" id="nama_unit" class="form-control" data-error="Please enter title." required disabled/>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label" for="title">Tanggal Aduan:</label>
<textarea name="created_at" class="form-control" id="tgl_aduan" data-error="Please enter description." readonly ></textarea>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label" for="title">Nama Pengadu:</label>
<input type="text" name="nama_pengadu" class="form-control" id="nama_pengadu" data-error="Please enter title." readonly />
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label> Isi Aduan </label>
<textarea name="aduan" id="aduan" class="form-control" rows="3" placeholder="Isi Aduan atau Keluhan ..." readonly ></textarea>
</div>
<div class="form-group">
<label class="control-label" for="title">Nama Teknisi:</label>
<input type="text" name="nama_teknisi" class="form-control" id="nama_teknisi" data-error="Please enter title." readonly />
<div class="help-block with-errors"></div>
</div>
----------------here this select2---------------------------
<div class="form-group">
<label>Pilih Inventaris</label>
<select class="form-control select2bs4" name="alat_id" id="alat_id" style="width: 100%;" aria-hidden="true">
#foreach($inven as $id => $item )
<option value="{{ $id }}">{{ $item }} </option>
#endforeach
</select>
</div>
--------------------------------------------------
<div class="form-group">
<label>Status Saat Ini (Jangan Lupa Diganti)</label>
<select name="status" id="status" class="form-control">
<option value="Tindakan Lanjutan">Tindakan Lanjutan</option>
<option value="Selesai">Selesai</option>
</select>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label> Tindakan Pelaksana </label>
<textarea name="tindakan" id="tindakan" class="form-control" rows="3" placeholder="Isi Tindakan Yang dilakukan" required ></textarea>
</div>
<div class="form-group">
<label>Kondisi Alat </label>
<select name="status_alat" id="status_alat" class="form-control">
<option value="Baik">Baik</option>
<option value="Rusak Ringan">Rusak Ringan</option>
<option value="Rusak Berat">Rusak Berat</option>
</select>
<div class="help-block with-errors"></div>
</div>
<input type="hidden" name="id" id="id" value="">
<input type="hidden" name="user_id" id="user_id" value="">
<input type="hidden" name="ipsrs_id" id="ipsrs_id" value="">
<input type="hidden" name="teknisi_id" id="teknisi_id" value="">
<input type="hidden" name="ended_at" id="ended_at" value="">
<div class="form-group">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button type="submit" id="button" class="btn btn-success crud-submit-edit button-prevent-multiple-submits">
<i class="spinner fa fa-spinner fa-spin" ></i>
Submit</button>
</div>
</form>
after using this select2 , will showing a new form . can someone references to me about this ?
//select input
<div class="form-group">
<label>Pilih Inventaris</label>
<select class="form-control select2bs4" name="alat_id" id="alat_id" style="width: 100%;" aria-hidden="true" onchange="Show()">
#foreach($inven as $id => $item )
<option value="{{ $id }}">{{ $item }} </option>
#endforeach
</select>
</div>
//new form
<div id="divid" style="display:none">
<form method="" action="">
#csrf
</form
<div>
//javascript code
<script>
function Show()
{
var fieldValue = $('#alat_id').val();
if(fieldValue == "")
{
document.getElementById("divid").style.display = 'none';
}
else{
document.getElementById("divid").style.display = 'inline'
}
}
</script>

Laravel csrf_field() Is Blank

I am learning about Packages in Laravel 5.4 and ultimately I will upload them to github.
This is my directory structure :
laravel
-vendor
--student
---myPackage
----src
-----Views
------myView.blade.php
the myView.blade.php has a form in it, and a {{csrf_field()}} function call, but when I inspect the output in the browser, the value attribute of the hidden input <input name="_token" value="" type="hidden"> is empty.
How do I make this work ?
SOLUTION
Apparantly, I needed to make sure that the web middleware is in use
for my routes, so I changed Route::get('/Register/{group}',
'Student\myPackage\Http\User#create'); to
Route::get('/Register/{group}',
'Student\myPackage\Http\User#create')->middleware('web');
Route:
Route::get('/Register/{group}', 'Student\myPackage\Http\User#create');
Route::post('/Register/{group}', 'Student\myPackage\Http\User#store');
Controller:
public function create($group){
return view('StudentUser::app', ['group' => $group]);
}
public function store($group)
{
dd(request()->all());
}
Form:
<form class="form-horizontal" role="form" method="POST" action="/Register/{{$group}}">
<div class="tab-content">
<div id="ap-about" class="tab-pane active">
{!! csrf_token() !!}
<div class="form-group">
<label for="name" class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control" name="name" value="" required autofocus>
</div>
</div>
<div class="form-group">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="" required>
</div>
</div>
<div class="form-group">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
</div>
</div>
<div class="form-group">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="button" class="btn btn-primary">
Next
</button>
</div>
</div>
</div>
<div id="ap-personal" class="tab-pane">
<div class="form-group">
<label for="address" class="col-md-4 control-label">Address</label>
<div class="col-md-6">
<input id="address" type="text" class="form-control" name="personal[]" value="" required autofocus>
</div>
</div>
<div class="form-group">
<label for="url" class="col-md-4 control-label">url</label>
<div class="col-md-6">
<input id="url" type="text" class="form-control" name="personal[]" value="" required autofocus>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Register
</button>
</div>
</div>
</div>
</div>
</form>

Create a table together with nested objects (columns)

In my Spring MVC application I am trying to build a complex form, where a table and the tables columns can be created at once.
When I submit my form, the table is created with all attributes, but it has not columns. Whats wrong with the nested objects?
This is my view:
<form id="form2" class="form-horizontal" action="/Weasy/virtualtable/insert" method="post">
<input type="hidden" id="isVirtual" name="isVirtual" value="true"/>
<input type="hidden" id="query" name="query" value="select * from aktie"/>
<input type="hidden" id="schema" name="schema" value="40"/>
<div class="form-group">
<div class="row">
<label class="col-sm-2 control-label" for="name"><i>Column No</i></label>
<label class="col-sm-2 control-label" for="name"><i>Column Name</i></label>
<label class="col-sm-2 control-label" for="name"><i>Database Type</i></label>
</div>
<div class="row">
<label class="col-sm-2 control-label" for="name"><i>0</i></label>
<label class="col-sm-2 control-label" for="name"><i>ID</i></label>
<div class="col-sm-5">
<input type="hidden" class="form-control" name="obj.columns[0].name" value="ID" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[0].datatype" value="INTEGER , Size: 11" placeholder="specify datatype">
</div>
</div>
<div class="row">
<label class="col-sm-2 control-label" for="name"><i>1</i></label>
<label class="col-sm-2 control-label" for="name"><i>BESCHREIBUNG</i></label>
<div class="col-sm-5">
<input type="hidden" class="form-control" name="obj.columns[1].name" value="BESCHREIBUNG" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[1].datatype" value="VARCHAR , Size: 255" placeholder="specify datatype">
</div>
</div>
<div class="row">
<label class="col-sm-2 control-label" for="name"><i>2</i></label>
<label class="col-sm-2 control-label" for="name"><i>ISIN</i></label>
<div class="col-sm-5">
<input type="hidden" class="form-control" name="obj.columns[2].name" value="ISIN" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[2].datatype" value="VARCHAR , Size: 255" placeholder="specify datatype">
</div>
</div>
<div class="row">
<label class="col-sm-2 control-label" for="name"><i>3</i></label>
<label class="col-sm-2 control-label" for="name"><i>WKN</i></label>
<div class="col-sm-5">
<input type="hidden" class="form-control" name="obj.columns[3].name" value="WKN" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[3].datatype" value="VARCHAR , Size: 255" placeholder="specify datatype">
</div>
</div>
<div class="row">
<label class="col-sm-2 control-label" for="name"><i>4</i></label>
<label class="col-sm-2 control-label" for="name"><i>NAME</i></label>
<div class="col-sm-5">
<input type="hidden" class="form-control" name="obj.columns[4].name" value="NAME" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[4].datatype" value="VARCHAR , Size: 255" placeholder="specify datatype">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="name"><i>Source Table</i></label>
<div class="col-sm-5">
<input type="text" class="form-control" id="name" name="name"
value="" placeholder="Virtual Table Name" required>
</div>
</div>
<div class="row">
<div class="col-sm-2"></div>
<div class="col-sm-2">
<input id="execQry" class="btn btn-block btn-primary btn-default"
type="submit" value="Save"
>
</div>
</div>
</div>
</form>
And this is the corresponding method of my controller. When I debug it, I see the table, but it has no columns.
#RequestMapping("insert")
public ModelAndView insert(#ModelAttribute SrcTable obj) {
return update(obj);
}
In your HTML you are trying to simulate a table with bootstrap, if you take a look at http://getbootstrap.com/css/#forms in form-horizontal section it can give you a more table-like structure, but in this case i recommend a table structure inside your form.
Example:
<input type="hidden" id="isVirtual" name="isVirtual" value="true"/>
<input type="hidden" id="query" name="query" value="select * from aktie"/>
<input type="hidden" id="schema" name="schema" value="40"/>
<table class="table">
<thead>
<tr>
<th><i>Column No</i></th>
<th><i>Column Name</i></th>
<th><i>Database Type</i></th>
</tr>
</thead>
<tbody>
<tr>
<td><i>0</i></td>
<td><i>ID</i></td>
<td>
<input type="hidden" class="form-control" name="obj.columns[0].name" value="ID" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[0].datatype" value="INTEGER , Size: 11" placeholder="specify datatype">
</td>
</tr>
<tr>
<td><i>1</i></td>
<td><i>BESCHREIBUNG</i></td>
<td>
<input type="hidden" class="form-control" name="obj.columns[1].name" value="BESCHREIBUNG" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[1].datatype" value="VARCHAR , Size: 255" placeholder="specify datatype">
</td>
</tr>
<tr>
<td><i>2</i></td>
<td><i>ISIN</i></td>
<td>
<input type="hidden" class="form-control" name="obj.columns[2].name" value="ISIN" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[2].datatype" value="VARCHAR , Size: 255" placeholder="specify datatype">
</td>
</tr>
<tr>
<td><i>3</i></td>
<td><i>WKN</i></td>
<td>
<input type="hidden" class="form-control" name="obj.columns[3].name" value="WKN" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[3].datatype" value="VARCHAR , Size: 255" placeholder="specify datatype">
</td>
</tr>
<tr>
<td><i>4</i></td>
<td><i>NAME</i></td>
<td>
<input type="hidden" class="form-control" name="obj.columns[4].name" value="NAME" placeholder="specify name">
<input type="text" class="form-control" name="obj.columns[4].datatype" value="VARCHAR , Size: 255" placeholder="specify datatype">
</td>
</tr>
</tbody>
</table>
<input id="execQry" class="btn btn-block btn-primary btn-default"
type="submit" value="Save"
>
</form>
While looking this over after a day pause, I found my error.
instead of
<input type="hidden" class="form-control" name="obj.columns[4].name" value="NAME" placeholder="specify name">
I had to use
<input type="hidden" class="form-control" name="columns[4].name" value="NAME" placeholder="specify name">

How to validate multiple value (Array of value ) in single Input (form) in codeigniter

this is the html part when i add more email id's only first email is being validated and rest of emails treat as normal even if they are not in proper
<form action="<?php echo base_url()?>index.php/EMail/show_email">
<div class="form-group">
<label for="exampleInputEmail1">To :</label>
<input type="email" name="toa[]" ng-model="to" placeholder="To" class=" tagsinput" value="ss" />
</div>
<div class="form-group">
<label for="exampleInputEmail1">Subject :</label>
<input type="text" class="form-control" ng-model="sub" name="suba" id="exampleInputEmail1" placeholder="Subject">
<div>{{sub}}</div>
</div>
<div class="form-group">
<label for="exampleInputEmail1">CC :</label>
<input type="text" class="form-control" ng-model="to" name="cca" id="exampleInputEmail1" placeholder="CC">
<div>{{to}}</div>
</div>
<div class="form-group">
<label for="exampleInputEmail1">BCC:</label>
<input type="text" class="form-control" name="bcca" id="exampleInputEmail1" placeholder="BCC">
</div>
<div class="form-group ">
<label for="ccomment" class="control-label">Message</label>
<textarea class="form-control " id="ccomment" name="msg" required></textarea>
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<input type="file" id="exampleInputFile">
<p class="help-block">Example block-level help text here.</p>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Check me out
</label>
</div>
<input type="submit" onclick="mail()" class="btn btn-primary" value="Send"/>
<button type="submit" class="btn btn-Success">Draft</button>
</form>
this is my controller and "toa "is that field which i mentioned in the image
function show_email(){
$this->form_validation->set_rules("toa[]","To","valid_email");
$this->form_validation->set_rules("cca","CC ","valid_email");
$this->form_validation->set_rules("suba","Subject","required");
$this->form_validation->set_rules("bcca","bcc","valid_email");
$this->form_validation->set_rules("msg","Message","required");
if($this->form_validation->run()==FALSE){
$data["title"]="EMail";
$this->load->view('header',$data);
$this->load->view('sidebar');
$this->load->view('Mail/mail');
}else{
//finish
$ccdata=$this->input->post("cca");
$bccdata=$this->input->post("bcca");
$sub=$this->input->post("suba");
$ms=$this->input->post("msg");
$dataa["username"]="MyProject";
$dataa["msg"]=$ms;
$msg=$this->load->view('Email_Temp/mail',$dataa,TRUE);
$todata=explode(",",$data);
print_r($todata[0]);
//$this->SendEmail($todata,$ccdata,$bccdata,$msg,$sub);
}
}
[Image] this is the field (to) that i want to validate

Resources