Code Monkey home page Code Monkey logo

Comments (5)

Anahkiasen avatar Anahkiasen commented on May 30, 2024

Well in theory Former would automatically populate the field with the roles if it matches the relation's name. That being said, I don't know how checkboxes handle the given value so I'm gonna take a look at it. But ideally yeah you wouldn't need more than this :

Former::populate($user)
Former::checkboxes('roles')

from former.

Anahkiasen avatar Anahkiasen commented on May 30, 2024

This should work now on the agnostic branch – can you try it out see if it works as intended for you ?

from former.

cviebrock avatar cviebrock commented on May 30, 2024

I've got the agnostic branch, and the same code as above. My $roles array is:

Array (
  [0] => Array (
    [label] => master
    [checked] => 1
  )
  [1] => Array (
    [label] => administrator
    [checked] => 
  )
)

The output I get is:

<div class="control-group">
  <label class="control-label">Roles</label>
  <div class="controls">
    <label for="1" class="checkbox">
      <input type="hidden" name="1" value="" id="1">
      <input id="1" type="checkbox" name="1" value="1">Master
    </label>
  </div>
</div>

So, two issues:

  1. It only seems to be outputting values that are set (i.e. the "Administrator" entry didn't output)
  2. The checkbox name should be roles[] not 1

Not sure if the setting of unchecked_value is going to affect things (can that be turned on/off on a per-checkbox basis?)

Thanks!

from former.

drpudding avatar drpudding commented on May 30, 2024

I realize this post is quite old, but have you ever found a solution for this. I am trying to do the same thing with Roles & Permissions. Show the entire list of permissions and then just those checked that are associated with the given role. Thanks for sharing if you have.

from former.

biwerr avatar biwerr commented on May 30, 2024

You have to add [] to the fieldname and pass an array with Key,Value to the function

Former::checkboxes('roles[]',"label",Role::all()->lists('name','id')->toArray());

from former.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.