bootstrap-select icon indicating copy to clipboard operation
bootstrap-select copied to clipboard

Bootstrap select doesn't send field data on form submit

Open ghost opened this issue 10 years ago • 59 comments

Hi,

I am having an issue with this plugin and I can't find a solution. I am using this with Laravel (even though I don't think it is relevant)

I have a multiple select which is works perfectly fine and it sends data on form submit. After I added the selectpicker class, the submitted value returns null. I really can't see why, because I used it many times and it worked perfectly fine.

`

<select id="user_categories" class="selectpicker" multiple="multiple" name="user_categories[]">  
<option value="1" selected="selected">Option 1</option>
<option value="2" selected="selected">Option 2</option>
</select>

`

Thanks!

ghost avatar Mar 26 '16 22:03 ghost

I have the same issue, using Bootstrap form-control class sends value properly, once I add selectpicker class this stops sending the value.

illbehere avatar Mar 31 '16 21:03 illbehere

See guidelines for contributing.

Bug reports

A bug is a demonstrable problem that is caused by the code in the repository. Good bug reports are extremely helpful - thank you!

Guidelines for bug reports:

  1. Use the GitHub issue search. Check if the issue has already been reported.
  2. Check if the issue has been fixed. Try to reproduce it using the latest master or development branch in the repository.
  3. Provide environment details. Provide your operating system, browser(s), jQuery version, Bootstrap version, and bootstrap-select version.
  4. Create an isolated and reproducible test case. Create a reduced test case.
  5. Include a live example. Make use of jsFiddle or jsBin to share your isolated test cases.

caseyjhol avatar Apr 01 '16 01:04 caseyjhol

I have the exact same issue. Upon removing the "selectpicker" class, the form data sends fine, adding the class again stops the data being sent with the form.

louis-marchant avatar May 01 '16 21:05 louis-marchant

I have the exact same issue, .

emresaracoglu avatar Aug 14 '16 11:08 emresaracoglu

See guidelines for contributing.

Bug reports

A bug is a demonstrable problem that is caused by the code in the repository. Good bug reports are extremely helpful - thank you!

Guidelines for bug reports:

  1. Use the GitHub issue search. Check if the issue has already been reported.
  2. Check if the issue has been fixed. Try to reproduce it using the latest master or development branch in the repository.
  3. Provide environment details. Provide your operating system, browser(s), jQuery version, Bootstrap version, and bootstrap-select version.
  4. Create an isolated and reproducible test case. Create a reduced test case.
  5. Include a live example. Make use of jsFiddle or jsBin to share your isolated test cases.

caseyjhol avatar Aug 15 '16 21:08 caseyjhol

Same issue, bump

The form doesn't pass any data, using Django the server spits an error "This field is required" indicating absolutely nothing was passed from the form fields when the submit button was clicked. Only happens when I'm using the selectpicker class on a ModelChoiceForm and DateField.

Once I remove the selectpicker class and use the out of the box selects the issue is resolved.

Form class ` class DonationForm(MySiteForm):

donor = forms.ModelChoiceField(queryset=Donor.objects.all(), widget=forms.Select(attrs={'class': 'selectpicker', 'data-live-search':'true', 'data-width':'350px'}))
date = forms.DateField(widget=SelectDateWidget(attrs={'class':'selectpicker', 'data-width':'114px'}))


class Meta:
    model = Donation
    fields = ('donor', 'date', 'type', 'est_val', 'description')`

` def donation_new(request):

if request.method == "POST":
    form = DonationForm(request.POST)
    if form.is_valid():
        donation = form.save(commit=False)
        #Manual form work here
        form.save()
        messages.success(request, 'New Donation succesfully added to database')
        return redirect('donations')
    else:
        print form.errors
else:
    form = DonationForm()
return render(request, 'habitatApp/donation_new.html', {'form': form})`

The HTML: `

<tr>

  <td><label for="id_donor">Donor</label>  <span class="asterik">* <span></td>

  <td>
      <select class="selectpicker" data-live-search="true" data-width="350px" id="id_donor" name="donor">

     <option value="" selected="selected">---------</option>

     <option value="3">Alec Robinson</option>

     <option value="4">Robinson Lyons</option>

     <option value="5">Reed Baum</option>

    </select> 
  </td>
  <td> </td>
  </tr>
  </div>`

nate-robo avatar Aug 31 '16 23:08 nate-robo

Browser? OS? Version of bootstrap-select? Example? Any more information about your setup? I've tested this and can't recreate it. If anybody can follow any of the guidelines for contributing, I'll be happy to look into this further.

caseyjhol avatar Aug 31 '16 23:08 caseyjhol

Chrome, OSX 10.11.1, bootstrap-select v 1.11.0

I'm using Django

The form.error output is as follows: Error: This field is required Error: this field is required This makes sense for the Django model because when I check the POST command after the submit button is clicked by the user, these two fields are showing up empty. The data from the selectpicker isn't being passed to the POST command despite selections being made. When I remove the class='selectpicker' from the html select, there is no longer issues passing the data.

Let me know if there's any other info you'd like

nate-robo avatar Sep 01 '16 01:09 nate-robo

Curious if you're still looking into this, please let me know. If you'd like me to submit some more details also more than willing, I couldn't follow your guidelines as it's impossible to create a JsFiddle that mimics the behavior in the Django framework.

nate-robo avatar Sep 02 '16 20:09 nate-robo

Would you be willing to email me a link to your site so I can demo it?

caseyjhol avatar Sep 03 '16 00:09 caseyjhol

My site is running locally e.g. (127.0.01/...), I could zip up my entire project and have you run it locally to debug it if you'd like?

nate-robo avatar Sep 07 '16 15:09 nate-robo

I ran into the same problem using Django and had a hard time debugging it. It appeared to be a typo in my template: I didn't properly close a table tag and used <table> instead of </table>. This wasn't so obvious, because the page layout still looked all right. Adding just 1 character solved my problem. Perhaps you should double check your HTML.

byrman avatar Oct 02 '16 15:10 byrman

@carlituxman So, the form submits properly when the elements are not inside a table? Is it possible you have the same issue as @byrman? I really can't think of anything that would be causing this issue other than an error in your HTML.

caseyjhol avatar Oct 25 '16 20:10 caseyjhol

I test some options but only fails inside a table. Without table it works

carlituxman avatar Oct 25 '16 21:10 carlituxman

What about other elements? For example, if you leave the code as is, but use a div tag instead of a table tag?

caseyjhol avatar Oct 25 '16 21:10 caseyjhol

This is my code:

<table class="table table-bordered table-striped">
            <thead>
                <tr>
                    <th class='col-xs-4'>Product</th>
                    <th class='col-xs-4'>Days</th>
                    <th class='col-xs-2'></th>
                </tr>
            </thead>

            <tbody>
                @foreach($data->products as $prod)
                    {!! Form::model($prod, array('files'=> true,'route' => array('myroute', $data->id))) !!}
                        {!! Form::hidden('producto_id',$prod->pivot->id) !!}
                        <tr>
                            <td>{{$prod->name}}</td>
                            <td>

                                {!! Form::select('dias[]', ['Lunes','Martes','Miércoles'], null, array('class'=> 'form-control selectpicker','multiple') )!!}

                            </td>
                            <td>
                                <button type="submit" class="btn btn-info btn-sm"><i class="fa fa-refresh"></i></button>
                            </td>
                        </tr>
                    {!! Form::close() !!}
                @endforeach
            </tbody>
        </table>

if quit the table then works, inside the table not send the post

carlituxman avatar Oct 26 '16 08:10 carlituxman

I add name attribute to the form and Its not working

2016-11-14 15:36 GMT+01:00 brizov43 [email protected]:

This happens when you do not add a name attribute of the form: ". Note the square bracket, it's important...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/silviomoreto/bootstrap-select/issues/1342#issuecomment-260350544, or mute the thread https://github.com/notifications/unsubscribe-auth/ACBJyqiANds8LXlM-FrKPEOtbDCIHPWtks5q-HHRgaJpZM4H5WIT .

Carlos Jiménez Mora INFORMATIK SOLUCIONES Tlf: 950 42 62 68 - Serón (Almería) @carlituxman https://twitter.com/carlituxman - [email protected]

Este mensaje y sus anexos pueden contener información confidencial, por lo que se informa de que su uso no autorizado está prohibido por la ley. Si Vd. considera que no es el destinatario pretendido por el remitente o no desea recibir información comercial, por favor póngalo en su conocimiento por esta misma vía o por cualquier otro medio y elimine esta comunicación y los anexos de su sistema, sin copiar, remitir o revelar los contenidos del mismo a cualquier otra persona. Cualquier información, opinión, conclusión, recomendación, etc. contenida en el presente mensaje no relacionada con la actividad empresarial de INFORMATIK BC SOLUCIONES S.L. y/o emitida por persona sin capacidad para ello, deberá considerarse como no proporcionada ni aprobada por INFORMATIK BC SOLUCIONES S.L. pone los medios a su alcance para garantizar la seguridad y ausencia de errores en la correspondencia electrónica, pero no puede asegurar la inexistencia de virus o la no alteración de los documentos transmitidos electrónicamente, por lo que declina cualquier responsabilidad a este respecto.

carlituxman avatar Nov 14 '16 16:11 carlituxman

@carlituxman Hi, I actually removed my post, because I noticed the others had the right name. It seems it's another problem. You should still check

  • <select name="somename[]">
  • <option value="uniqueValue">
  • if the fields are inside the form (between the form tags)
  • when the fields are in a <fieldset> tag don't forget the form="yourForm" attribute I worked through my problem with these steps.

brizov43 avatar Nov 14 '16 16:11 brizov43

Any one solved this issue ! I have the exactly same issue as you, someone found a solution about this please ?

miranos avatar Dec 01 '16 21:12 miranos

Guys I had the same issue later to realize that I am missing the name attribute, I have attached a sample code and it is working fine on both browsers Firefox 50.1.0, and Chrome 55.0.2883.87 (64-bit) running ubuntu 64-bit 16.04 LTS. http://stackoverflow.com/questions/27216187/bootstrap-select-plugin-how-to-submit-the-form-with-it <form role="form" id="form" action="/action" method="post"> <table class="table" <tr> <th> <select class="selectpicker form-control" title="colour" id="type" name="colour"> <option>red</option> <option>black</option> /select> </th> </tr> </table> <div class="col-sm-12"> <button type="submit" class="btn btn-success btn-block" id="add_colour">ADD</button> </div> </form>

ka-sh avatar Jan 09 '17 07:01 ka-sh