Halo semuanya, apa kabar? Semoga sehat selalu, Amin. Kali ini kita akan belajar tutorial bonus untuk fitur stock-in (pembelian) yaitu bagaimana cara membuat detail data setelah stock-in bisa tampil di pop-up atau modal bootstrap dengan menggunakan framework CodeIgniter, jQuery, dan template AdminLTE.
Bagi yang ketinggalan silakan cek urutan lengkap Seri Tutorial POS di Daftar Isi dari blog ini.
Langsung saja cara buat seperti yang ada di judul, bisa kita pelajari pada video di bawah ini.
Bagaimana sudah berhasil? Lanjut ke tutorial selanjutnya ya ..
Jika artikel ini bermanfaat, silakan share ke teman-teman Anda.
Jangan lupa untuk subscribe channel youtube YukCoding Media dan follow instagram @yukcoding. Terimakasih. Happy coding 🙂
Before getting started with Bootstrap’s modal component, be sure to read the following as our menu options have recently changed.
Modals are built with HTML, CSS, and JavaScript. They’re positioned over everything else in the document and remove scroll from the so that modal content scrolls instead.
Clicking on the modal “backdrop” will automatically close the modal.
Bootstrap only supports one modal window at a time. Nested modals aren’t supported as we believe them to be poor user experiences.
Modals use
Launch demo modal
Modal title
...
Close
Save changes
3, which can sometimes be a bit particular about its rendering. Whenever possible, place your modal HTML in a top-level position to avoid potential interference from other elements. You’ll likely run into issues when nesting a
Launch demo modal
Modal title
...
Close
Save changes
4 within another fixed element.
Once again, due to
Launch demo modal
Modal title
...
Close
Save changes
3, there are some caveats with using modals on mobile devices. for details.
Due to how HTML5 defines its semantics, has no effect in Bootstrap modals. To achieve the same effect, use some custom JavaScript:
var myModal = document.getElementById('myModal')
var myInput = document.getElementById('myInput')
myModal.addEventListener('shown.bs.modal', function () {
myInput.focus()
})
Keep reading for demos and usage guidelines.
Examples
Modal components
Below is a static modal example (meaning its
Launch demo modal
Modal title
...
Close
Save changes
7 and
Launch demo modal
Modal title
...
Close
Save changes
8 have been overridden). Included are the modal header, modal body (required for
Launch demo modal
Modal title
...
Close
Save changes
9), and modal footer (optional). We ask that you include modal headers with dismiss actions whenever possible, or provide another explicit dismiss action.
Modal body text goes here.
Modal title
Modal body text goes here.
Close
Save changes
Live demo
Toggle a working modal demo by clicking the button below. It will slide down and fade in from the top of the page.
Woohoo, you're reading this text in a modal!
Launch demo modal
Modal title
...
Close
Save changes
Static backdrop
When backdrop is set to static, the modal will not close when clicking outside it. Click the button below to try it.
I will not close if you click outside me. Don't even try to press escape key.
Launch static backdrop modal
Launch static backdrop modal
Modal title
...
Close
Understood
When modals become too long for the user’s viewport or device, they scroll independent of the page itself. Try the demo below to see what we mean.
This is some placeholder content to show the scrolling behavior for modals. Instead of repeating the text the modal, we use an inline style set a minimum height, thereby extending the length of the overall modal and demonstrating the overflow scrolling. When content becomes longer than the height of the viewport, scrolling will move the modal as needed.
You can also create a scrollable modal that allows scroll the modal body by adding
Launch static backdrop modal
Modal title
...
Close
Understood
0 to
Launch static backdrop modal
Modal title
...
Close
Understood
1.
This is some placeholder content to show the scrolling behavior for modals. We use repeated line breaks to demonstrate how content can exceed minimum inner height, thereby showing inner scrolling. When content becomes longer than the prefedined max-height of modal, content will be cropped and scrollable within the modal.
This content should appear at the bottom after you scroll.
...
Vertically centered
Add
Launch static backdrop modal
Modal title
...
Close
Understood
2 to
Launch static backdrop modal
Modal title
...
Close
Understood
1 to vertically center the modal.
This is a vertically centered modal.
This is some placeholder content to show a vertically centered modal. We've added some extra copy here to show how vertically centering the modal works when combined with scrollable modals. We also use some repeated line breaks to quickly extend the height of the content, thereby triggering the scrolling. When content becomes longer than the prefedined max-height of modal, content will be cropped and scrollable within the modal.
Tooltips and popovers can be placed within modals as needed. When modals are closed, any tooltips and popovers within are also automatically dismissed.
Utilize the Bootstrap grid system within a modal by nesting
Launch static backdrop modal
Modal title
...
Close
Understood
4 within the
Launch static backdrop modal
Modal title
...
Close
Understood
5. Then, use the normal grid system classes as you would anywhere else.
Level 1: .col-sm-9
Level 2: .col-8 .col-sm-6
Level 2: .col-4 .col-sm-6
.col-md-4
.col-md-4 .ms-auto
.col-md-3 .ms-auto
.col-md-2 .ms-auto
.col-md-6 .ms-auto
Level 1: .col-sm-9
Level 2: .col-8 .col-sm-6
Level 2: .col-4 .col-sm-6
Varying modal content
Have a bunch of buttons that all trigger the same modal with slightly different contents? Use
Launch static backdrop modal
Modal title
...
Close
Understood
6 and HTML
Launch static backdrop modal
Modal title
...
Close
Understood
7 attributes to vary the contents of the modal depending on which button was clicked.
Below is a live demo followed by example HTML and JavaScript. For more information, for details on
Launch static backdrop modal
Modal title
...
Close
Understood
8.
Open modal for @mdo Open modal for @fat Open modal for @getbootstrap
Open modal for @mdo
Open modal for @fat
Open modal for @getbootstrap
New message
Close
Send message
var exampleModal = document.getElementById('exampleModal')
exampleModal.addEventListener('show.bs.modal', function (event) {
// Button that triggered the modal
var button = event.relatedTarget
// Extract info from data-bs-* attributes
var recipient = button.getAttribute('data-bs-whatever')
// If necessary, you could initiate an AJAX request here
// and then do the updating in a callback.
//
// Update the modal's content.
var modalTitle = exampleModal.querySelector('.modal-title')
var modalBodyInput = exampleModal.querySelector('.modal-body input')
modalTitle.textContent = 'New message to ' + recipient
modalBodyInput.value = recipient
})
Toggle between modals
Toggle between multiple modals with some clever placement of the
Launch static backdrop modal
Modal title
...
Close
Understood
9 and
...
0 attributes. For example, you could toggle a password reset modal from within an already open sign in modal. Please note multiple modals cannot be open at the same time—this method simply toggles between two separate modals.
Show a second modal and hide this one with the button below.
Hide this modal and show the first with the button below.
Modal title
Modal body text goes here.
Close
Save changes
0
Change animation
The
...
1 variable determines the transform state of
Launch static backdrop modal
Modal title
...
Close
Understood
1 before the modal fade-in animation, the
...
3 variable determines the transform of
Launch static backdrop modal
Modal title
...
Close
Understood
1 at the end of the modal fade-in animation.
If you want for example a zoom-in animation, you can set
...
5.
Remove animation
For modals that simply appear rather than fade in to view, remove the
...
6 class from your modal markup.
Modal title
Modal body text goes here.
Close
Save changes
1
Dynamic heights
If the height of a modal changes while it is open, you should call
...
7 to readjust the modal’s position in case a scrollbar appears.
Accessibility
Be sure to add
...
8, referencing the modal title, to
Launch demo modal
Modal title
...
Close
Save changes
4. Additionally, you may give a description of your modal dialog with
...
...
0 on
Launch demo modal
Modal title
...
Close
Save changes
4. Note that you don’t need to add
...
...
2 since we already add it via JavaScript.
Embedding YouTube videos
Embedding YouTube videos in modals requires additional JavaScript not in Bootstrap to automatically stop playback and more. See this helpful Stack Overflow post for more information.
Optional sizes
Modals have three optional sizes, available via modifier classes to be placed on a
Launch static backdrop modal
Modal title
...
Close
Understood
1. These sizes kick in at certain breakpoints to avoid horizontal scrollbars on narrower viewports.SizeClassModal max-widthSmall
Full screen Full screen below sm Full screen below md Full screen below lg Full screen below xl Full screen below xxl
Modal title
Modal body text goes here.
Close
Save changes
3
Sass
Variables
Modal title
Modal body text goes here.
Close
Save changes
4
Loop
are generated via the
.col-md-4
.col-md-4 .ms-auto
.col-md-3 .ms-auto
.col-md-2 .ms-auto
.col-md-6 .ms-auto
Level 1: .col-sm-9
Level 2: .col-8 .col-sm-6
Level 2: .col-4 .col-sm-6
3 map and a loop in
.col-md-4
.col-md-4 .ms-auto
.col-md-3 .ms-auto
.col-md-2 .ms-auto
.col-md-6 .ms-auto
Level 1: .col-sm-9
Level 2: .col-8 .col-sm-6
Level 2: .col-4 .col-sm-6
4.
Modal title
Modal body text goes here.
Close
Save changes
5
Usage
The modal plugin toggles your hidden content on demand, via data attributes or JavaScript. It also overrides default scrolling behavior and generates a
.col-md-4
.col-md-4 .ms-auto
.col-md-3 .ms-auto
.col-md-2 .ms-auto
.col-md-6 .ms-auto
Level 1: .col-sm-9
Level 2: .col-8 .col-sm-6
Level 2: .col-4 .col-sm-6
5 to provide a click area for dismissing shown modals when clicking outside the modal.
Via data attributes
Activate a modal without writing JavaScript. Set
.col-md-4
.col-md-4 .ms-auto
.col-md-3 .ms-auto
.col-md-2 .ms-auto
.col-md-6 .ms-auto
Level 1: .col-sm-9
Level 2: .col-8 .col-sm-6
Level 2: .col-4 .col-sm-6
6 on a controller element, like a button, along with a
.col-md-4
.col-md-4 .ms-auto
.col-md-3 .ms-auto
.col-md-2 .ms-auto
.col-md-6 .ms-auto
Level 1: .col-sm-9
Level 2: .col-8 .col-sm-6
Level 2: .col-4 .col-sm-6
7 or
.col-md-4
.col-md-4 .ms-auto
.col-md-3 .ms-auto
.col-md-2 .ms-auto
.col-md-6 .ms-auto
Level 1: .col-sm-9
Level 2: .col-8 .col-sm-6
Level 2: .col-4 .col-sm-6
8 to target a specific modal to toggle.
Modal title
Modal body text goes here.
Close
Save changes
6
Via JavaScript
Create a modal with a single line of JavaScript:
Modal title
Modal body text goes here.
Close
Save changes
7
Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to
.col-md-4
.col-md-4 .ms-auto
.col-md-3 .ms-auto
.col-md-2 .ms-auto
.col-md-6 .ms-auto
Level 1: .col-sm-9
Level 2: .col-8 .col-sm-6
Level 2: .col-4 .col-sm-6
9, as in
Open modal for @mdo
Open modal for @fat
Open modal for @getbootstrap
New message
Close
Send message
0.NameTypeDefaultDescription
Open modal for @mdo
Open modal for @fat
Open modal for @getbootstrap
New message
Close
Send message
1boolean or the string
Open modal for @mdo
Open modal for @fat
Open modal for @getbootstrap
New message
Close
Send message
2
Open modal for @mdo
Open modal for @fat
Open modal for @getbootstrap
New message
Close
Send message
3Includes a modal-backdrop element. Alternatively, specify
Open modal for @mdo
Open modal for @fat
Open modal for @getbootstrap
New message
Close
Send message
4 for a backdrop which doesn't close the modal on click.
Open modal for @mdo
Open modal for @fat
Open modal for @getbootstrap
New message
Close
Send message
5boolean
Open modal for @mdo
Open modal for @fat
Open modal for @getbootstrap
New message
Close
Send message
3Closes the modal when escape key is pressed
Open modal for @mdo
Open modal for @fat
Open modal for @getbootstrap
New message
Close
Send message
7boolean
Open modal for @mdo
Open modal for @fat
Open modal for @getbootstrap
New message
Close
Send message
3Puts the focus on the modal when initialized.
Methods
Asynchronous methods and transitions
All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.
.
Passing options
Activates your content as a modal. Accepts an optional options
Open modal for @mdo
Open modal for @fat
Open modal for @getbootstrap
New message
Close
Send message
9.
Modal title
Modal body text goes here.
Close
Save changes
8
toggle
Manually toggles a modal. Returns to the caller before the modal has actually been shown or hidden (i.e. before the
var exampleModal = document.getElementById('exampleModal')
exampleModal.addEventListener('show.bs.modal', function (event) {
// Button that triggered the modal
var button = event.relatedTarget
// Extract info from data-bs-* attributes
var recipient = button.getAttribute('data-bs-whatever')
// If necessary, you could initiate an AJAX request here
// and then do the updating in a callback.
//
// Update the modal's content.
var modalTitle = exampleModal.querySelector('.modal-title')
var modalBodyInput = exampleModal.querySelector('.modal-body input')
modalTitle.textContent = 'New message to ' + recipient
modalBodyInput.value = recipient
})
0 or
var exampleModal = document.getElementById('exampleModal')
exampleModal.addEventListener('show.bs.modal', function (event) {
// Button that triggered the modal
var button = event.relatedTarget
// Extract info from data-bs-* attributes
var recipient = button.getAttribute('data-bs-whatever')
// If necessary, you could initiate an AJAX request here
// and then do the updating in a callback.
//
// Update the modal's content.
var modalTitle = exampleModal.querySelector('.modal-title')
var modalBodyInput = exampleModal.querySelector('.modal-body input')
modalTitle.textContent = 'New message to ' + recipient
modalBodyInput.value = recipient
})
1 event occurs).
show
Manually opens a modal. Returns to the caller before the modal has actually been shown (i.e. before the
var exampleModal = document.getElementById('exampleModal')
exampleModal.addEventListener('show.bs.modal', function (event) {
// Button that triggered the modal
var button = event.relatedTarget
// Extract info from data-bs-* attributes
var recipient = button.getAttribute('data-bs-whatever')
// If necessary, you could initiate an AJAX request here
// and then do the updating in a callback.
//
// Update the modal's content.
var modalTitle = exampleModal.querySelector('.modal-title')
var modalBodyInput = exampleModal.querySelector('.modal-body input')
modalTitle.textContent = 'New message to ' + recipient
modalBodyInput.value = recipient
})
0 event occurs).
Also, you can pass a DOM element as an argument that can be received in the modal events (as the
Launch static backdrop modal
Modal title
...
Close
Understood
8 property).
Modal title
Modal body text goes here.
Close
Save changes
9
hide
Manually hides a modal. Returns to the caller before the modal has actually been hidden (i.e. before the
var exampleModal = document.getElementById('exampleModal')
exampleModal.addEventListener('show.bs.modal', function (event) {
// Button that triggered the modal
var button = event.relatedTarget
// Extract info from data-bs-* attributes
var recipient = button.getAttribute('data-bs-whatever')
// If necessary, you could initiate an AJAX request here
// and then do the updating in a callback.
//
// Update the modal's content.
var modalTitle = exampleModal.querySelector('.modal-title')
var modalBodyInput = exampleModal.querySelector('.modal-body input')
modalTitle.textContent = 'New message to ' + recipient
modalBodyInput.value = recipient
})
1 event occurs).
handleUpdate
Manually readjust the modal’s position if the height of a modal changes while it is open (i.e. in case a scrollbar appears).
dispose
Destroys an element’s modal. (Removes stored data on the DOM element)
getInstance
Static method which allows you to get the modal instance associated with a DOM element
Launch demo modal
Modal title
...
Close
Save changes
0
getOrCreateInstance
Static method which allows you to get the modal instance associated with a DOM element, or create a new one in case it wasn’t initialised
Launch demo modal
Modal title
...
Close
Save changes
1
Events
Bootstrap’s modal class exposes a few events for hooking into modal functionality. All modal events are fired at the modal itself (i.e. at the
Apa itu bootstrap modal?
Membuat Modal dengan Bootstrap – Modal atau yang biasa di sebut pop up pada bootstrap adalah sebuah kotak dialog yang biasanya di gunakan untuk melakukan konfirmasi atas suatu aksi. Misal, ketika anda ingin menghapus suatu data, anda bisa menggunakan modal ini sebagai pesan konfirmasi atas aksi apa yang anda lakukan.
Apa itu modal dalam HTML?
Modal adalah kotak dialog yang muncul pada halaman web. Cara kerja modal adalah ketika modal dalam kondisi aktif maka dialog box akan tampil dan halaman utamanya menjadi tidak aktif, namun halaman utama tetap dapat terlihat pada jendela browser.