I've been using remodal for confirmation and notification pop-ups. What I fail to do so is allowing enter key submission. I tried searching for a solution, but it seems there are none on the web and the developer seems to be abandoned his work before the enter key issue is solved.
I tried using javascript switch-case codes but again, this creates a problem of changing focus if user decides to click something responsive before pressing the enter key, in addition, this method turns out to be extremely time consuming.
I turn around these 3 clues:
Clue 1: When a remodal window is opened, data-remodal-id
attribute of div becomes the window location. Example = ../mypage.php#myremodal
Clue 2: Confirmation buttons have this attribute: data-remodal-action="confirm"
Clue 3: Remodal window is put front of page z-index.
I am trying to find a way that would simply simulate a .click()
on confirm button of currently opened remodal. As I said, I tried switch(from){}
inside opened remodal section and assigned from = $(e.currentTarget).attr("data-remodal-id");
in order to select which modal is confirmed, but this creates other problems due to structure and extemely time consuming for all confirmations to apply.
This is how remodal actions are controlled in the script:
$(document).on('opening', '.remodal', function() {
console.log('Modal is opening');
});
$(document).on('opened', '.remodal', function() {
//**************************************************
//THIS IS WHERE I WANT TO PUT ENTER KEY CONFIRMATION
//**************************************************
console.log('Modal is opened');
});
$(document).on('closing', '.remodal', function(e) {
// Reason: 'confirmation', 'cancellation'
console.log('Modal is closing' + (e.reason ? ', reason: ' + e.reason : ''));
});
$(document).on('closed', '.remodal', function(e) {
// Reason: 'confirmation', 'cancellation'
console.log('Modal is closed' + (e.reason ? ', reason: ' + e.reason : ''));
});
$(document).on('confirmation', '.remodal', function() {
console.log('Confirmation button is clicked');
from = window.location.hash.substr(1)
switch (from){
case "1":
//*********************
// MY JSON ACTIONS HERE
//*********************
break;
case "2":
//*********************
// MY JSON ACTIONS HERE
//*********************
break;
}
});
$(document).on('cancellation', '.remodal', function() {
console.log('Cancel button is clicked');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/remodal/1.1.1/remodal.min.js"></script>
<div class="remodal" data-remodal-id="myremodal">
<button data-remodal-action="close" class="remodal-close"></button>
<p>
some text
</p>
<br>
<button data-remodal-action="cancel" class="remodal-cancel">Cancel</button>
<button data-remodal-action="confirm" class="remodal-confirm">OK</button>
</div>
<a data-remodal-target="myremodal">call the modal</a>