Move CRUD edit button into the form DOM element

This commit is contained in:
Riyyi
2021-05-10 15:50:39 +02:00
parent 541b1de8de
commit 230b580909
2 changed files with 4 additions and 2 deletions
+2 -1
View File
@@ -57,9 +57,10 @@
<?php } ?> <?php } ?>
</div> </div>
<?php } ?> <?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; ?>" /> <input type="hidden" name="_token" value="<?= $this->csrfToken; ?>" />
</form> </form>
<button class="js-edit btn btn-dark" href="<?= $this->url . '/' . $this->model->id; ?>">Edit</button>
<div class="pb-5"></div> <div class="pb-5"></div>
</div> </div>
+2 -1
View File
@@ -25,6 +25,7 @@ $(document).ready(function() {
// Edit // Edit
$('.js-edit').on('click', function(event) { $('.js-edit').on('click', function(event) {
event.preventDefault();
// Trigger HTML5 form validation // Trigger HTML5 form validation
var valid = $('#form-edit')[0].reportValidity(); var valid = $('#form-edit')[0].reportValidity();
@@ -32,7 +33,7 @@ $(document).ready(function() {
return; return;
} }
var href = $(this).attr('href'); var href = $(this).attr('data-href');
$.ajax({ $.ajax({
url: href, url: href,
type: "PUT", type: "PUT",