cretueusebiu / vform

Handle Laravel-Vue forms and validation with ease.
https://vform.vercel.app
MIT License
607 stars 120 forks source link

Form Fill (Edit Mode) #94

Closed George2215 closed 4 years ago

George2215 commented 4 years ago

Hi,

I request help me with this situation, I am trying to show a form to edit it but the idrol field returns an object, how can I access it to show me the user's role correctly

<div class="form-group row">
     <label class="col-md-3 form-control-label" for="text-input">Asignar Rol</label>
      <div class="col-md-9">
            <select class="form-control" :class="{'is-invalid': form.errors.has('idrol')}" 
                   v-model="form.idrol"
                   name="idrol">
                  <option value="0" disabled>Seleccione Rol</option>
                  <option v-for="role in arrayRoles" :key="role.id" :value="role.id" v-text="role.name">
                  </option>
            </select>
             <has-error :form="form" field="idrol"></has-error>                                       
          </div>
</div>

Without using the fill method, I can access the property as follows this.idrol =data['roles'][0].id it shows the role, but in this way I would not be taking advantage of the benefits of the vform package

Edit Method

editModal(user){
                console.log(user);                
                let me =this;        
                me.form.reset();
                me.form.clear();
                me.modal=1;
                me.tipoAccion =2;
                me.form.fill(user);                
            },

My Controller

public function index(Request $request)
    {        
        if (!$request->ajax()) 
            return redirect('/');

        $name = $request->get('name'); //Captura el dato ingreso en el campo name

        $users = User::search($name)->with('roles')->orderBy('id','DESC')->paginate(10);

        //$userRole = $user->roles->pluck('name','name')->all();

        return [
                'pagination' => [
                'total'        => $users->total(),
                'current_page' => $users->currentPage(),
                'per_page'     => $users->perPage(),
                'last_page'    => $users->lastPage(),
                'from'         => $users->firstItem(),
                'to'           => $users->lastItem(),
                ],
                'users' => $users            
            ];
    }

I appreciate your help