Why is v-if not working with v-model in this example? - vue.js

I have a form where I am trying to switch between province or state depending on the country chosen in a select box. In my DB Canada = 001 and USA = 002. Here is my code:
<form action="{{ route('store') }}" method="post" id="vueApp" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="col-md-12 mb-4">
<label for="student[country]">Country</label>
<select class="form-control form-control-sm col-md-6" id="student[country]" name="student[country]" v-model="country">
<option value selected>None</option>
#foreach($countries as $code => $description)
<option value="{{ $code }}">{{ $description }}</option>
#endforeach
</select>
</div>
<div v-if="country == '001'" class="col-md-12 mb-4">
<label for="student[province]">Province</label>
<select class="form-control form-control-sm col-md-6" id="student[province]" name="student[province]">
<option value>None</option>
#foreach($states_provinces->where('xcomment', 'Canada')->pluck('short_desc', 'state_code') as $code => $description)
<option value="{{ $code }}" {{ old('student.province') == $code ? 'selected' : '' }}>{{ $description }}</option>
#endforeach
</select>
</div>
<div v-else-if="country == '002'" class="col-md-12 mb-4">
<label for="student[province]">State</label>
<select class="form-control form-control-sm col-md-6" id="student[province]" name="student[province]">
<option value selected>None</option>
#foreach($states_provinces->where('xcomment', 'USA')->pluck('short_desc', 'state_code') as $code => $description)
<option value="{{ $code }}" {{ old('student.province') == $code ? 'selected' : '' }}>{{ $description }}</option>
#endforeach
</select>
</div>
<div v-else>
<input type="hidden" class="form-control form-control-sm col-md-6" id="student[province]" max="255" name="student[province]" value="">
</div>
</form>
<script>
(function(){
var $country = '{{ old('student.country') }}';
var app = new Vue({
el: '#vueApp',
data: {
country: $country === '' ? '001' : $country,
},
});
</script>
It shows both province and state in the form no matter which country is chosen. Nothing changes, any help would be gladly appreciated! I did previously have an error, "Uncaught TypeError: Vue is not a constructor", but I was able to remove that error by removing the '$' before (function()) after the script tag. Still the same result, looks like it isn't recognizing my vue directives.
Result

Related

VueJS dynamic inputs avoid duplicates

I have a project where I allow users to add filters to alerts, what is the best way to avoid dupliated filters and to let users add one filter of each type?
<div class="filters_container" v-for="filter in alert.filters">
<div class="form-group">
<select class="form-control" v-model="filter.type">
<option disabled selected value="0">Select</option>
<option value="price">Price</option>
<option value="sales">Sales</option>
<option value="margin" v-if="alert.tool == 'classic'">Margin</option>
<option value="trend">Trending items</option>
</select>
</div>
<div class="form-group" v-if="filter.type == 'sales'">
<label>Time frame</label>
<select class="form-control" v-model="filter.timeFrame">
<option disabled selected value="0">Select</option>
<option value="daily">Daily</option>
<option value="weekly">Weekly</option>
<option value="monthly">Monthly</option>
<option value="total">Total</option>
</select>
</div>
<div class="form-group" v-if="filter.type != 'trend'">
<label>Values</label>
<div class="form-row">
<div class="col">
<input type="text" class="form-control" v-model="filter.min" placeholder="Min">
</div>
<div class="col">
<input type="text" class="form-control" v-model="filter.max" placeholder="Max">
</div>
</div>
</div>
</div>
<button type="submit" class="btn btn-success btn-sm" #click.prevent="addFilter">Add Filter</button>
This is my add filter function at the moment
addFilter: function () {
this.alert.filters.push(
{
temp_id: (Math.floor(Math.random() * 1000)) * (Date.now()),
type: 'trend',
timeFrame: 'daily',
min: null,
max: null
}
)
},
You can use the following function:
this.alert.filters = this.alert.filters.filter((value, index, self) =>
{
return index === self.findIndex(item =>
{
return item.type === value.type; // && item.timeFrame === value.timeFrame && item.min === value.min && item.max === value.max;
});
});

HubSpot custom module to display data from hubdb and search filter

I'm trying to create a custom module in HubSpot to display data from hubdb and i also to make a search filter so that users can search for some specific info on the pay but i'm having some issue with the filter. Could anyone assist me? Below is my code so far.
Here is my hubDB Table column (i'm using dynamic pages):
| hs_name | hs_path | title | decription | country | date | location | language | image | url |
search filter screenshot and Display of the data screenshot
<div class="container mt-5 filter">
<div class="row">
<div class="col-md-6 mt-0 filter-search" style="text-align: left;">
<input type="text" id="myInput" placeholder="Search..." />
</div>
<div class="col-sm-2 filter-section">
<select class="country">
<option value="all">All Country</option>
<option value="UK"> UK </option>
<option value="BE"> Belgium </option>
</select>
</div>
<div class="col-sm-2 filter-section">
<select class="language">
<option value="all">Language</option>
<option value="English"> English </option>
<option value="French"> French</option>
</select>
</div>
<div class="col-sm-2 filter-section">
<select class="tags">
<option value="all">Tags</option>
<option value="Virtual">Virtual</option>
<option value="Physical">Physical</option>
</select>
</div>
</div>
</div>
<div class="container FilterContainer mt-5">
{% set current_dt = unixtimestamp( local_dt ) %}
  {% set query = "date__lt="~current_dt~"&orderBy=-date" %}
  {% set table = hubdb_table_rows(<hubdbTableId>, query) %}
{% for row in table %}
<div class="card column" data-country="{{ row.country == "BE" }}" data-language="{{ row.language == "English" }}" data-tag="{{ row.country == "Virtual" }}">
<div class="row no-gutters">
<div class="col-md-4">
<img src="{{ row.image.url }}" alt="Banner" class="img-fluid h-100" />
</div>
<div class="col-md-6">
<div class="card-body">
<p class="card-text">
<span class="badge badge-pill">{{ row.country }}</span>
<span class="badge badge-pill"> <i class="fa fa-calendar"></i> {{ row.date|datetimeformat(('%B %e, %Y')) }}</span>
<span class="badge">{{ row.location }}</span>
<span class="badge badge-pill">{{ row.language }}</span>
</p>
<h5 class="card-title"><strong>
{{ row.title }}</strong></h5>
<p><strong>Decription: </strong>{{ row.decription }}</p>
</div>
</div>
<div class="event-detail-border"></div>
<div class="col-md-2 btn-body">
Read More
</div>
</div>
</div>
{% endfor %}
</div>
<script>
$("select.country, select.language, select.tags").change(updateEvents);
$("#myInput").on("keyup", updateEvents);
function updateEvents() {
var country = $('select.country').val();
var language = $('select.language').val();
var tags = $('select.tags').val();
var search = $("#myInput").val();
$('.FilterContainer')
.find('.column')
.hide()
.filter(function() {
var okCountry = true;
var okLanguage = true;
var okTags = true;
var okSearch = true;
if (country !== "all") {
okCountry = $(this).attr('data-country') === country;
}
if (language !== "all") {
okLanguage = $(this).attr('data-language') === language;
}
if (tags !== "all") {
okTags = $(this).attr('data-teacher') === tags;
}
if (search !== '') {
okSearch = $(this).text().toLowerCase().indexOf(search) > -1;
}
//only fade a room if it satisfies all four conditions
return okCountry && okLanguage && okTags && okSearch;
}).fadeIn('fast');
}
</script>

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'status_member' cannot be null

i have failed to save update data, the notification error message is SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'status_member' cannot be null (SQL: update daftar_pelanggans set alamat = gdsgzddgrrse, status_member = ?, daftar_pelanggans.updated_at = 2020-12-06 03:36:35 where id = 6)
this is the button edit
<button data-toggle="modal" data-target="#editModal-{{ $pelanggan->id }}" class="btn btn-sm btn-primary"><i class="fa fa-edit"></i></button>
this is the modal view
#foreach($daftar_pelanggan as $pelanggan)
<div class="modal fade" id="editModal-{{ $pelanggan->id }}" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title mb-0" id="editModalLabel">Update Data Pelanggan</h5>
</div>
<div class="modal-body">
<!-- Card body -->
<form role="form" action="{{ route('daftar_pelanggan.update', $pelanggan->id) }}" method="POST" id="editForm">
#csrf
#method('PUT')
<!-- Input groups with icon -->
<div class="form-group row">
<label for="updateNamaPelanggan" class="col-md-2 col-form-label form-control-label">Nama</label>
<div class="col-md-10">
<input type="hidden" name="id" value="{{ $pelanggan->id }}">
<input class="form-control" type="nama" value="{{ $pelanggan->nama_pelanggan }}" name="updateNamaPelanggan" required >
</div>
</div>
<div class="form-group row">
<label for="updateAlamat" class="col-md-2 col-form-label form-control-label">Alamat</label>
<div class="col-md-10">
<input class="form-control" type="alamat" value="{{ $pelanggan->alamat }}" name="updateAlamat" required>
</div>
</div>
<div class="form-group row">
<label for="updateNoTelp" class="col-md-2 col-form-label form-control-label">No.Telp</label>
<div class="col-md-10">
<input class="form-control" type="notelp" value="{{ $pelanggan->no_telp }}" name="updateNoTelp" required>
</div>
</div>
<div class="form-group row">
<div class="col-md-6">
<div class="form-group">
<label class="form-control-label" for="updatePoin">POIN</label>
<input type="text" class="form-control" value="{{ $pelanggan->poin }}" name="updatePoin">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="form-control-label" for="status_member">Kategori</label>
<!-- <h3>{{ $pelanggan->status_member }}</h3>-->
<select class="form-control" name="status_member" required="required">
<option value="silver" {{ $pelanggan->status_member === 'Silver' ? 'selected' : '' }} >Silver</option>
<option value="gold" {{ $pelanggan->status_member === 'Gold' ? 'selected' : '' }} >Gold</option>
<option value="diamond" {{ $pelanggan->status_member === 'Diamond' ? 'selected' : '' }} >Diamond</option>
</select>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="reset" class="btn btn-secondary" data-dismiss="modal">Reset</button>
<button type="submit" class="btn btn-primary">Update Data</button>
</div>
</form>
</div>
</div>
</div>
#endforeach
this is the route
Route::put('daftar_pelanggan/update/{id}', '\App\Http\Controllers\DaftarPelangganController#update')->name('daftar_pelanggan.update');
and this is the controller
public function update(Request $request, $id)
{
$update_pelanggan = DaftarPelanggan::find($id);
$update_pelanggan->nama_pelanggan = $request->updateNamaPelanggan;
$update_pelanggan->alamat = $request->updateAlamat;
$update_pelanggan->no_telp = $request->updateNoTelp;
$update_pelanggan->poin = $request->updatePoin;
$update_pelanggan->status_member = $request->updateKategori;
$update_pelanggan->save();
if($simpan){
Alert::success(' Berhasil Tambah data ', ' Silahkan dicek kembali');
}else{
Alert::error('data gagal disimpan ', ' Silahkan coba lagi');
}
return redirect()->back();}
what's wrong with this code ?
You have named the select control as status_member in the form while you are using $request->updateKategori in controller method/action while saving update data.
You can cross check by dd($request->all()) as first line of the update method and check which key value pairs are available as request data.
Change the update method like
public function update(Request $request, $id)
{
$update_pelanggan = DaftarPelanggan::findOrFail($id);
$update_pelanggan->nama_pelanggan = $request->updateNamaPelanggan;
$update_pelanggan->alamat = $request->updateAlamat;
$update_pelanggan->no_telp = $request->updateNoTelp;
$update_pelanggan->poin = $request->updatePoin;
//name of key $request->status_member must match name=status_member on select control in the form
$update_pelanggan->status_member = $request->status_member;
$update_pelanggan->save();
//------------- OR you can simply do ---------------------------//
//$update_pelanggam = DaftarPelanggan::findOrFail($id);
//$update_pelaggan->update($request->all();
//-------------------------------------------------------------//
if($simpan){
Alert::success(' Berhasil Tambah data ', ' Silahkan dicek kembali');
}else{
Alert::error('data gagal disimpan ', ' Silahkan coba lagi');
}
return redirect()->back();
}

select input in blazor Server side getting option's text as its value onchange event

I have a problem binding a select on Server side blazor. The passed on the onchange event is the options text(label).
Here is my select element:
<div class="form-group row">
<div class="form-group col-md-6">
<label>Role</label>
<select class="form-control form-control form-control-sm"
placeholder="Role"
disabled="#IsReadOnly"
#onchange="(e) => RoleChanged(e)">
<option value="">Select Role...</option>
<option value="Member">Member</option>
<option value="Admin">Admin</option>
<option value="Pioneer">Pioneer</option>
<option value="Retailer">Retailer</option>
</select>
<ValidationMessage For="#(() => Model.Role)" class="row" />
</div>
Upon debugging the RoleChanged method
It gets the option text as Value when the event is triggered.
Also the client validation is not firing
Refactor you code to use form components :
<div class="form-group row">
<div class="form-group col-md-6">
<label>Role</label>
<InputSelect class="form-control form-control form-control-sm"
placeholder="Role"
disabled="#IsReadOnly" Value="Model.Role" ValueChanged="RoleChanged" ValueExpression="#(() => Model.Role)">
<option value="">Select Role...</option>
<option value="Member">Member</option>
<option value="Admin">Admin</option>
<option value="Pioneer">Pioneer</option>
<option value="Retailer">Retailer</option>
</InputSelect >
<ValidationMessage For="#(() => Model.Role)" class="row" />
</div>
// an async method must return Task or ValueTask
private async Task RoleChanged(string value)
{
// your logic
}

Problem with select, v-model that change other component

I have this code with vue.js. I simplified the code for the question.
The problem is WHEN I CHANGE THE PROVINCE, AUTOMATICALLY MY SECOND SELECT
"selectProCongeFam" CHANGE TOO. I don't know why exactly.
Here is the code :
const deduction = {!! json_encode($deduction->toArray()) !!};
const provinces = {!! json_encode($provinces) !!};
new Vue({
el: '#app',
data: function () {
return {
provinces: provinces,
province: deduction['province']
}
}
})
<div class="row">
<div class="col-xs-12 col-sm-6 col-lg-3 mb-4">
<div class="form-group">
<label>Province
<select class="form-control"
name="province" id="province" v-model="province">
<option v-for="(name,value) in provinces" :value="value">
#{{name}}
</option>
</select>
</label>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-lg-3 mb-4">
<div class="form-group">
<label for="selectProCongeFam">#lang('form.extFamily')
<select id="selectProCongeFam" name="proCongeFam"
class="form-control">
<option value="0"
:selected="deduction['proCongeFam'] == 0">#lang('form.no')</option>
<option value="1" :selected="deduction['proCongeFam'] == 1">#lang('form.yes')</option>
<option value="2" :selected="deduction['proCongeFam'] == 2">#lang('form.yesbutILD')</option>
<option value="3" :selected="deduction['proCongeFam'] == 3">#lang('form.AMConly')</option>
</select>
</label>
</div>
</div>