Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue-multiselect issue on edit #11

Open
vue-fan opened this issue Jan 9, 2020 · 9 comments
Open

vue-multiselect issue on edit #11

vue-fan opened this issue Jan 9, 2020 · 9 comments

Comments

@vue-fan
Copy link

vue-fan commented Jan 9, 2020

Hi,
how to set selected the option when i'm editing?
i follow all the example from 'articles-with-relationship'
but i dont know why the multiselect doesn't set the value.

@mediaboost
Copy link

same problem ...

@mediaboost
Copy link

Ok you have to pass the object selected by from controller

example

$category_selected = $realisation->categorie;

@elshobokshy
Copy link

elshobokshy commented Feb 14, 2020

@mediaboost how to set it ? :value='value' doesn't seem to work

@mediaboost
Copy link

example :

add categorie prop in Form.js

in form-element-right.blade.php see v-model

pass the value from controller
$categorie = $realisation->categorie;

done :)

@mediaboost
Copy link

v-model="form.categorie"

@elshobokshy
Copy link

elshobokshy commented Feb 14, 2020

@mediaboost thanks for the quick answer!

I'm passing roles_id which gives me back 1

return view('admin.admin-user.edit', [
        'adminUser' => $adminUser,
        'activation' => Config::get('admin-auth.activation_enabled'),
        'roles' => Role::get(),
        'roles_id' => $adminUser->roles->pluck('id')->toArray()[0]
]);

And I got this in my form :

<multiselect 
    v-model="roles_id" 
    placeholder="Roles" 
    label="..." 
    track-by="id" 
    :options="{{ $roles->toJson() }}" 
    open-direction="bottom" 
    deselect-label="">
</multiselect>

Knowing that {{ $roles->toJson() }} returns :

[
  {"id":1,"name":"Administrator","guard_name":"admin","created_at":"2020-02-14 11:29:23","updated_at":"2020-02-14 11:29:23"},
  {"id":2,"name":"Publisher","guard_name":"publisher","created_at":"2020-02-14 11:29:23","updated_at":"2020-02-14 11:29:23"},
  {"id":3,"name":"Member","guard_name":"member","created_at":"2020-02-14 11:29:23","updated_at":"2020-02-14 11:29:23"}
]

But it doesn't work. Any idea why?

@mediaboost
Copy link

Re ...

on va passer en français car je vois que tu l'es :)

ton roles_id de ton controller n'est pas bon si le multiselect n'est pas multiple
il faut envoyer l'objet entier de ton role_id de ta table (je présume) en faisant une relation dans ton modele de type belongs_to

donc dans ton exemple tu dois avoir
'roles' => Role::all(),
'role_id' => $adminUser->role (pas de pluck etc)

ensuite tu dois ajouter une propriété role_id dans ton form_js et pour finir ajouter dans ton v_model
form.role_id

ensuite si c'est affichage multiple ... il faut tester en envoyant $adminUser->roles

@elshobokshy
Copy link

elshobokshy commented Feb 14, 2020

@mediaboost merci!

Voici donc le résultat final :

<multiselect v-model="form.role_id" placeholder="{{ trans('admin.forms.select_options') }}" label="name" track-by="id" :options="{{ $roles->toJson() }}" open-direction="bottom" deselect-label=""></multiselect>

avec roles qui renvoie

[{"id":1,"name":"Administrator","guard_name":"admin","created_at":"2020-02-14 11:29:23","updated_at":"2020-02-14 11:29:23"},
{"id":2,"name":"Publisher","guard_name":"publisher","created_at":"2020-02-14 11:29:23","updated_at":"2020-02-14 11:29:23"},
{"id":3,"name":"Member","guard_name":"member","created_at":"2020-02-14 11:29:23","updated_at":"2020-02-14 11:29:23"}]

et role_id qui renvoie :

[{"id":1,"name":"Administrator","guard_name":"admin","created_at":"2020-02-14 11:29:23","updated_at":"2020-02-14 11:29:23"}]

J'ai rajouté dans mon Form.js le champ. Et pourtant aucun résultat toujours ! Très frustrant ^^"

@elshobokshy
Copy link

elshobokshy commented Feb 14, 2020

@mediaboost ok très bizarre, avec exactement ce que tu as dis ça marche appart le champ dans v-model qui doit être égal à v-model="form.roles" pour que ça marche, et quand j'enlève role_id de mon controller ça ne marche plus. Donc en gros il faut définir role_id et quand même utiliser v-model="form.roles" ... Je ne comprend pas pourquoi ça marche mais merci lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants