When to use v-model in vue.js? - php

I'm using ci4 and vue.js to create a drop-down list. I'm confuse when to use a v-model and when not to use.
I try to view selected data in drop-down list. When I use a v-model, the selected data doesn't view in my drop-down list.
`
<div class="input-group mb-3" style="width: 500px;">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa-solid fa-location-dot"></i></span>
</div>
<select class="form-control" v-model="sel_kod_negara" :class="{'is-invalid': error.kod_negara}">
<option value="">-Select Country-</option>
<option :value="selected.di_kod_negara" selected>{{selected.keterangan}}</option>
<option :value="r.kod" v-for="r in kod_negara">{{r.keterangan}}</option>
</select>
</div>
`
the picture below show when i put the v-model
enter image description here
When I delete the v-model from my attributes drop-down list, the selected data will view. It's any problem if I'm not use a v-model in my drop-down list attributes?
the picture below show when i don't put the v-model
enter image description here
Any advise please? Thank you!

Related

Laravel view show data based on option selected

Inside my view, I have a Modal (vue component), in which there is a select with 3 options (admin, user, manager) and I want to display in the Modal all the registers for the role selected.
<modal-component id="showGroups">
<div class="form-group">
<select class="form-control">
<option disabled>Choose a role</option>
<option>admin</option>
<option>user</option>
<option>manager</option>
</select>
</div>
#foreach
<p>User register for the role {{ user->role }}</p>
#endforeach
</modal-component>
I'm struggling with this

How to return value from different cell of table column by foreign key id in Laravel 8.*

I made view that adds edits data, to database, its table got foreign keys. So for request I need its id. Can i somehow display name of it while under will be ids?
Im sorry if title is missleading, i dont know how to ask about this properly
In my controller im using both tables for foreign and master keys
Im doing it using this: (i dont know how its called)
Form code
<div class="form-group col-md-4">
<label for="inputState">City</label>
<select id="inputState" name="city_id" class="form-control">
<option selected >{{ $data->city_id }}</option>
#foreach($city as $city)
<option>{{ $city->id }}</option>
#endforeach
</select>
</div>
I think this is you're looking for. On edit, you pass the $data and $city properties to blade and on loop you can make selected the option in select element if the condition is checked
<div class="form-group col-md-4">
<label for="inputState">City</label>
<select id="inputState" name="city_id" class="form-control">
<option value="">Select</option>
#foreach($city as $city)
<option value="{{ $city->id }}" #if($city->id == $data->city_id) selected #endif>{{ $city->name }}</option>
#endforeach
</select>
</div>

Multiselect Box with Laravel and values from database

I am having difficulty with multi-select boxes with Laravel, particularly, reading values from the database and displaying these values so they can be edited in my edit view.
In my controller, in the store function, I am using the implode function to save positive integers into a database field.
Here is the implode function
$prodmulti = implode(',', $prodmulti);
The database stores these values in a cell such as
prodmulti
1,2,3
This works fine and I get the cell, populated with values fine.
The problem is when I wish to edit these values.
If I have nothing saved in this cell, then as expected, I have nothing in the multi-select box which is good.
If I have 1 number in the database cell, then again, it is fone, I can see the corresponding item in the multi-select box.
If I have 2 or more items in the database cell, then the multi-select box shows as blank in the edit view. This is where I am having my problem.
The view blade for the edit page with the multi-select box looks like this:
<div class="col-lg-8 col-xl-5">
<div class="form-group">
<select class="js-select2 form-control" name="prodmulti[]" style="width: 100%;" multiple>
<option></option>
#foreach($productcategories as $productcategory)
<option value="{{ $productcategory->id }}" {{ $user->prodmulti == $productcategory->id ? "selected" : ""}}>
{{ $productcategory->name }}
</option>
#endforeach
</select>
</div>
</div>
And the show function in the controller looks like this where I use the explode to extract the values as an array as such.
$prodmulti = explode(',', $prodmulti);
return view(
'admin.users.edit',
compact([
'user',
'roles',
'countries',
'states',
'productcategories',
'prodmulti'
])
);
If it helps, here is my create a view where I again use one of these multi-select boxes to add values
<div class="col-lg-8 col-xl-5">
<div class="form-group">
<select class="js-select2 form-control" id="prodmulti" name="prodmulti[]" style="width: 100%;" data-placeholder="Choose many.." multiple>
<option></option>
#foreach($productcategories as $productcategory)
<option value="{{ $productcategory->id }}">
{{ $productcategory->name }}
</option>
#endforeach
</select>
</div>
</div>
Finally, I am using select2 multi-select boxes, but I get the same result if I use just standard bootstrap multi-select boxes and have tried both, I just like the look of the select2 multi-select boxes.
Any help would be greatly appreciated,
Thanks,
Steve.
use in_array() to check
$prodmulti = explode(',', $prodmulti);
return view('admin.users.edit', compact(['user', 'roles', 'countries', 'states', 'productcategories', 'prodmulti']));
then in blade
<div class="col-lg-8 col-xl-5">
<div class="form-group">
<select class="js-select2 form-control" id="prodmulti" name="prodmulti[]" style="width: 100%;" data-placeholder="Choose many.." multiple>
<option></option>
#foreach($productcategories as $productcategory)
<option value="{{ $productcategory->id }}"
{{ in_array($productcategory->id,$prodmulti) ? "selected" : "" }}>
{{ $productcategory->name }}
</option>
#endforeach
</select>
</div>
</div>

Display Dropdown in HTML with PHP

I am android developer and making one admin panel for one of my android application. I know very basic PHP. currently I am displaying input field with value and user can change with text input and can save value with submit button. Its like below
<div class="form-group">
<label class="col-md-3 control-label">Admob On/off :-</label>
<div class="col-md-6">
<input type="text" name="ads_status" id="ads_status" value="<?php echo $settings_row['ads_status'];?>" class="form-control">
</div>
</div>
Instead of input value I want show dropdown menu with two item called on and off. When user load page it should show value based on previous save. Like if user have made setting on it must display on. I am displaying value now from database. Let me know if anyone can suggest me what Should I do for it. Thanks
<div class="form-group">
<label class="col-md-3 control-label">Admob On/off :-</label>
<div class="col-md-6">
<select class="form-control " type="text" name="ads_status" >
<option value="on" <?php if($settings_row['ads_status']== 'on') echo "selected = 'selected'" ?> >On</option>
<option value="off" <?php if($settings_row['ads_status'] == 'off') echo "selected = 'selected'" ?> >Off</option>
</select>
</div>
</div>
I hope this will hep you.

how to grab database values to edit form in dropdown input in laravel

I am developing web application using laravel. In my application I have data entry form and in this form I have one optional value selections input
<label for="status" class="control-label">Choose Status</label>
<select name="status" id="status">
<option value="">Choose a status</option>
<option value="Upcoming">Upcoming</option>
<option value="Active">Active</option>
<option value="Completed">Completed</option>
</select>
#if ($errors->has('status'))
<span class="help-block">{{ $errors->first('status') }}</span>
#endif
Now I need develop edit data form some of my data in the data table. In this form I need show selection input field in edit page with current values in the data table. and select optional values if user go to the edit. then how can I develop selection field in the edit blade file.
Edited
<select name="assign" id="status">
<option value="{!! $task->assign !!}">{!! $task->assign !!}</option>
{{ getstatus($task->assign) }}
</select>
#if ($errors->has('assign'))
<span class="help-block">{{ $errors->first('assign') }}</span>
#endif
what about this edited optional input fields. it is working but not displaying other optional values.

Categories