简体   繁体   中英

Checkbox included into form from child view by ajax is not detected by post method

I made ajax live search in my form and now paginated data/html comes from child view with ajax and js help. Search returns a checkbox, so I mark this checkbox and click submit/post and in dumpdata I cannot see this selected checkbox. Page inspection shows such code after ajax search is performed:

<tr>
 <td>
  <div class="form-chceck">
   <input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="56">
   <label class="form-check-label" for="exampleRadios1">
                        56
            </label>
  </div>
 </tr>
</td>

If I put something like that directly into my blade form view instead of:

     @csrf
     <tbody>
     @include('projects/projects_child')       
     </tbody>

then it works fine.

Ajax:

 $.ajax({
   url:"/projects/projects/fetch_data?page="+page+"&sortby="+sort_by+"&sorttype="+sort_type+"&query="+query,
   success:function(data)
   {
    $('tbody').html('');
    $('tbody').html(data);
   }
  })

What could be the issue?

Adding a checkbox value isn't the same as making a checkbox as checked. What you did just means when it's checked it's value will be 56. I believe this is what you're looking for:

<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios1" value="56" checked>

You can wrap that attribute in an @if or something if you need to in your blade template.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM