Comments (2)
i also tried now a different approach using relations for some simple static dropdown values
and basicly ended up with this approach:
public function edit(ServiceFall $serviceFall)
{
$this->authorize('admin.service-fall.edit', $serviceFall);
$serviceFall->load('ServiceStatus');
return view('admin.service-fall.edit', [
'serviceFall' => $serviceFall,
'ServiceStatusList'=> ServiceStatus::getRows()
]);
}
having a hasOne relationship to
public function ServiceStatus(){
return $this->hasOne(ServiceStatus::class,'id','service_status_id');
}
class ServiceStatus extends Model
{
use \Sushi\Sushi;
static function getRows()
{
return [
['id' => 1, 'name' => 'admin 1'],
['id' => 2, 'name' => 'admin 2'],
['id' => 3, 'name' => 'admin 3'],
['id' => 4, 'name' => 'admin 4'],
['id' => 5, 'name' => 'admin 5'],
['id' => 6, 'name' => 'admin 6'],
['id' => 7, 'name' => 'admin 7'],
];
}
}
and i also added the props etc to the forms.js
Vue.component('service-fall-form', {
mixins: [AppForm],
props: [
'ServiceStatusList'
],
data: function() {
return {
form: {
ServiceShortDescription: '' ,
ServiceLongDescription: '' ,
service_status_id: '' ,
ServiceCreatedByUser: '' ,
},
mediaCollections: ['gallery']
}
}
});
template:
{{ $serviceFall->ServiceStatus}}
<div class="form-group row align-items-center" :class="{'has-danger': errors.has('ServiceStatus'), 'has-success': fields.ServiceStatus && fields.ServiceStatus.valid }">
<label for="roles" class="col-form-label text-md-right" :class="isFormLocalized ? 'col-md-4' : 'col-md-2'">{{ trans('admin.admin-user.columns.roles') }}</label>
<div :class="isFormLocalized ? 'col-md-4' : 'col-md-9 col-xl-8'">
<multiselect v-model="form.ServiceStatus" placeholder="{{ trans('brackets/admin-ui::admin.forms.select_options') }}" label="name" track-by="id" :options="{{ json_encode($ServiceStatusList) }}" :multiple="false" open-direction="bottom"></multiselect>
<div v-if="errors.has('ServiceStatus')" class="form-control-feedback form-text" v-cloak>@{{ errors.first('ServiceStatus') }}</div>
</div>
</div>
i see that ServiceStatus getting properly set by my load method to for example {"id":5,"name":"admin 5"}
but still, its not selecting this value as default from the multiselect :/
from craftable.
Hi @mzanier 👋
You can preselect multiselect by prefilling v-model
value. In your code, if I understand correctly, you use v-model="form.ServiceStatus"
for multiselect so something like this should work:
Vue.component('service-fall-form', {
mixins: [AppForm],
props: [
'ServiceStatusList',
'serviceFall'
],
data: function() {
return {
form: {
ServiceShortDescription: '' ,
ServiceLongDescription: '' ,
service_status_id: '' ,
ServiceCreatedByUser: '' ,
ServiceStatus: serviceFall.ServiceStatus.id
},
mediaCollections: ['gallery']
}
}
});
Notice I added serviceFall
to props and added ServiceStatus
to form attribute with a default value. Notice that serviceFall.ServiceStatus.id
might not work out of the box, since I'm not familiar with your code that well, but the point is you can use whatever value you want, you can even pass it from controller.
Please let me know if this helped you or not 🤗
from craftable.
Related Issues (20)
- ERROR : Can't install at all HOT 9
- Improve AdminListing pagination to allow customize page name attribute HOT 2
- Improve Media Library to use max fize size value from config
- I will redesign the readme.md HOT 1
- Enhancement of README.md HOT 3
- Cannot install the installer HOT 2
- Listing columns empty HOT 1
- 14 Warnings about slash-div when runing npm HOT 1
- Not compatible with Laravel 9 (with Vite) HOT 1
- pagination not working if primary key name is not 'id' HOT 3
- WHAT IS THE PASSWORD??????? HOT 2
- Craftable Install aborts installation HOT 9
- Base table or view not found: 1146 Table 'testblog.permissions' doesn't exist HOT 7
- Problem installing Craftable Installer globally HOT 2
- Support for Laravel 10 / PHP 8 HOT 11
- Translations are not saved - "The GET method is not supported" HOT 3
- Declaration of Brackets\AdvancedLogger\Formatters\LineWithHashFormatter incompatible with Monolog\Formatter\LineFormatter - Laravel 10 HOT 2
- after use craftable install, .env file always set DB_PASSWORD=password...thats make error in database HOT 3
- Issue with Generated CRUD Menu in Laravel Craftable HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from craftable.