Giter Club home page Giter Club logo

Comments (6)

sileence avatar sileence commented on May 28, 2024

Can you please submit the full code that is causing the error and the full HTML generated? I need to see the full line without the ......

Thanks.

from html.

sistemasjg avatar sistemasjg commented on May 28, 2024

Template:
{!! Field::selectmultiple('categorias[]', [], [], ['label'=>'Categorias', 'multiple ', 'id'=>'categorias', 'data-placeholder'=>'Seleccione una o más Categorias', 'class'=>'chosen-select'] )!!}

Original code produces:

<select multiple="multiple " id="categorias[]" data-placeholder="Seleccione una o mas categorias" class="form-control chosen-select" name="categorias[]"></select>

causing var c = $('#categorias'); and var c = $('#categorias[]'); to fail

Updated Code produces:

<select multiple="multiple " id="categorias" data-placeholder="Seleccione una o más Categorias" class="form-control chosen-select" name="categorias[]"></select>

allowing

var c = $('#categorias'); to work and add selected and available items via jquery/ajax calls

from html.

sileence avatar sileence commented on May 28, 2024

the name of the field (categorias[]) doesn't make sense to me, can't it be just "categorias"?

from html.

sileence avatar sileence commented on May 28, 2024

Also if you'd like to have a field like post[categories] or something like that, write it as:

{!! Field::select("post.categories") !!}

The component will then generate the appropriate name post[categories] and the ID post_categories

from html.

sistemasjg avatar sistemasjg commented on May 28, 2024

If I name it just categorias, without the brackets,

the ajax call for saving data throws

Argument 1 passed to Illuminate\Database\Eloquent\Relations\BelongsToMany::formatSyncList() must be of the type array, string given, called in ...

$p->categorias()->sync($ct);

FormData (headers)
_token:zftpV77sX5ToChV7EYAnZifHGN2CkSkrBCOuGX7Y categorias:24 categorias:26 categorias:27 id:61

in the controller, where the form is submited a call to dd($request::get('categorias'));
returns just "27"

putting the brackets in the name, all works as expected.

Is a ManyToMany Relationship, where the edited model is submited with the selected categories its belongs. I've read in laravel docs and forums that multiselect name must include brackets to allow laravel submit this field as an array.

Also if you'd like to have a field like post[categories] or something like that, write it as >>"post.categories" the component will then generate the appropriate name post[categories] and >>the ID post_categories

Let me test it this way. The problem is than I'm filling selected and available categories via jquery/ajax/modal, and because of that, I'm can't use the laravel model/blade syntax in javascript/jquery calls. At least, don't know if is possible

from html.

sistemasjg avatar sistemasjg commented on May 28, 2024

You can see the same problem in core laravel form builder, back in 2013

laravel/framework#853

from html.

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.