mercredi 14 novembre 2018

laravel update method ignores fields from hidden modal

I have a little form like this:

<form action="/" method="POST" class="form-horizontal">


<div class="form-group">
    <label for="formGroupExampleInput">Name:</label>
    <input type="text" id="name" name="name" class="form-control" value="">
</div>
<div id="ex1" class="modal row selects col-md-9" style="background-color:transparent;">
  <div class="form-row col-sm-9">
    <div class="col">
    <label>Hud 1</label>
      <select id="w_hud1" name="w_hud1">
        <option>---Select---</option>
      </select>
    </div>
  </div>
</div>
<div class="form-group">
  <div class="col-sm-offset-3 col-sm-6">
    <button type="submit" class="btn btn-default">
      <i class="fa fa-btn fa-plus">update</i>
    </button>
  </div>
</div>

My update function:

public function update(Request $request, equip $equip)
 {
   $this->validate($request, [
       'name'       => 'required',
       'w_hud1'     => 'nullable'
   ]);
   $equip->update($request->all());
   return back();
 }

When I hit the update button the value of the select box won't be recognized by the update function - the var_dump of $request would be:

array(3) { ["_token"]=> string(40) "UFu6APAKP4gkyKFFxR7q6zTkPAFPSteLG0j7eU3u" ["_method"]=> string(5) "PATCH" ["name"]=> string(1) "1" }

But when I remove the "Modal" class from the div the value will be passed:

array(4) { ["_token"]=> string(40) "UFu6APAKP4gkyKFFxR7q6zTkPAFPSteLG0j7eU3u" ["_method"]=> string(5) "PATCH" ["name"]=> string(1) "1" ["w_hud1"]=> string(6) "203832" }

So it has something to do with the class. Source of the class "Modal":

https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.css

Any idea why this is happening? I hope I gave enough information.

Regards,

Andreas



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire