Skip to content

Instantly share code, notes, and snippets.

@LucianoCharlesdeSouza
Last active January 12, 2021 01:03
Show Gist options
  • Save LucianoCharlesdeSouza/ce61044fa923dbea228052a61561954c to your computer and use it in GitHub Desktop.
Save LucianoCharlesdeSouza/ce61044fa923dbea228052a61561954c to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
<body>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal1">
modal 1
</button>
<!-- Modal 1 -->
<div class="modal fade" id="modal1" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="first">First</label>
<input type="text" class="form-control" id="first"/>
</div>
<div class="form-group">
<label for="last">Last</label>
<input type="text" class="form-control" id="last"/>
</div>
<div class="form-group">
<label for="handle">Handle</label>
<input type="text" class="form-control" id="handle"/>
</div>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal2">
add
</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<!-- Modal 2 -->
<div class="modal fade" id="modal2" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel2" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabe2">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th scope="col">Selecione</th>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"><input type="checkbox" class="modalCheckbox"></th>
<th scope="row">1</th>
<td class="first">Mark</td>
<td class="last">Otto</td>
<td class="handle">@mdo</td>
</tr>
<tr>
<th scope="row"><input type="checkbox" class="modalCheckbox"></th>
<th scope="row">2</th>
<td class="first">Jacob</td>
<td class="last">Thornton</td>
<td class="handle">@fat</td>
</tr>
<tr>
<th scope="row"><input type="checkbox" class="modalCheckbox"></th>
<th scope="row">3</th>
<td class="first">Larry</td>
<td class="last">the Bird</td>
<td class="handle">@twitter</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<script>
$(function () {
$('.modalCheckbox').change(function () {
let check = $(this)
let checked = check.is(":checked");
if (checked) {
let row = check.closest('tr')
$('#first').val(row.find('.first').text())
$('#last').val(row.find('.last').text())
$('#handle').val(row.find('.handle').text())
check.prop('checked', false)
$('#modal2').modal('toggle')
}
})
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment