Browse Source

Move CRUD edit button into the form DOM element

master
Riyyi 4 years ago
parent
commit
230b580909
  1. 3
      app/views/admin/crud/edit.php
  2. 3
      public/js/app.js

3
app/views/admin/crud/edit.php

@ -57,9 +57,10 @@
<?php } ?>
</div>
<?php } ?>
<button type="submit" class="js-edit btn btn-dark" data-href="<?= $this->url . '/' . $this->model->id; ?>">Edit</button>
<input type="hidden" name="_token" value="<?= $this->csrfToken; ?>" />
</form>
<button class="js-edit btn btn-dark" href="<?= $this->url . '/' . $this->model->id; ?>">Edit</button>
<div class="pb-5"></div>
</div>

3
public/js/app.js

@ -25,6 +25,7 @@ $(document).ready(function() {
// Edit
$('.js-edit').on('click', function(event) {
event.preventDefault();
// Trigger HTML5 form validation
var valid = $('#form-edit')[0].reportValidity();
@ -32,7 +33,7 @@ $(document).ready(function() {
return;
}
var href = $(this).attr('href');
var href = $(this).attr('data-href');
$.ajax({
url: href,
type: "PUT",

Loading…
Cancel
Save