Uncaught TypeError: this.dialogTarget is null (v1.x) #16
-
Hello, I've just setup a Rails 7 environment using @rolemodel/turbo-confirm, and the confirmation modal doesn't present. I did test that before installing turbo-confirm, that the default confirm modal does work with turbo_confirm. I'm getting the following error in Firefox, Web developer debugger: (Here's first 4 lines of output from the debugger)
Here's my configuration: Rails 7.1.2, turbo-rails (1.5.0) importmap.rb javascript/application..js
html.erb using link_to: <%= link_to "Log Out", logout_path, class: "dropdown-item", Thanks in advance for any help. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
@nrichardson1951 Thank you for your question! Do you have any elements on your page with the data attribute
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick response. I placed your example dialogue on the page and now don’t get the “Uncaught Type error”,
so, it’s finding the element id, but the dialogue box doesn’t show. I noticed a comment in the README, that the dialogue
isn’t visible without a ‘modal—active’ class. I tried adding ‘modal—active’ to the dialogue template, but still no joy.
Where does that class definition need to be defined or what else am I missing?
Thanks for your patience.
From: Braden Rich ***@***.***>
Sent: Wednesday, December 6, 2023 5:09 PM
To: RoleModel/turbo-confirm ***@***.***>
Cc: nrichardson1951 ***@***.***>; Mention ***@***.***>
Subject: Re: [RoleModel/turbo-confirm] Rails 7 -- RoleModel Turbo-Confirm error --"Uncaught TypeError: this.dialogTarget is null" (Discussion #16)
@nrichardson1951 <https://github.com/nrichardson1951> Thank you for your question! Do you have any elements on your page with the data attribute id? The way we have things setup internally, we have something like this:
<div class="modal-wrapper flex items-center justify-center modal-wrapper--active" id="confirm">
<div class="modal-wrapper__backdrop confirm-cancel"></div>
<div class="modal text-center margin-md card-padded">
<h3 id="confirm-title">Are you sure?</h3>
<div class="margin-bottom-lg" id="confirm-body">
<p>This action cannot be undone.</p>
</div>
<div class="flex justify-center items-center gap-sm">
<button class="confirm-cancel btn btn-primary btn--outline" id="confirm-cancel">Cancel</button>
<button class="btn-delete" id="confirm-accept">Yes, I'm Sure</button></div></div></div>
—
Reply to this email directly, view it on GitHub <#16 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/AUC22O6BTFTA524CVU77ND3YIDUI5AVCNFSM6AAAAABAKBQJ76VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TOOBRHAYTA> .
You are receiving this because you were mentioned. <https://github.com/notifications/beacon/AUC22O6PQXO55K4NDRVCQKLYIDUI5A5CNFSM6AAAAABAKBQJ76WGG33NNVSW45C7OR4XAZNRIRUXGY3VONZWS33OINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAO263E.gif> Message ID: ***@***.*** ***@***.***> >
|
Beta Was this translation helpful? Give feedback.
-
Thank you for your update as it helped me to understand what I needed to make it work for a bootstrap modal.
Here’s my configuration:
1. application.js
RoleModelConfirm.init()
2. Bootstrap modal definition
<div class="modal fade" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true" id="confirm">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="confirm-title">Are you sure?</h3>
<button type="button" class="btn-close confirm-cancel" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="confirm-body">
<!-- <p>This action cannot be undone.</p> -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary confirm-cancel" data-bs-dismiss="modal" id="confirm-cancel">Cancel</button>
<button type="button" class="btn btn-primary" id="confirm-accept">Yes, I'm Sure</button>
</div>
</div>
</div>
</div>
3. Using link_to
<%= link_to 'Log Out', logout_path, class: 'dropdown-item',
data: { \
turbo_method: :delete,
turbo_confirm: 'Are you Sure?',
confirm_button: 'Yes'
}
%>
4. Update to ConfirmationController.js for showing a bootstrap modal.
Note: It looks like there’s a way to pass Javascript to RoleModelConfirm.init() for showConfirmCallback, but I’m not sure how to do it, so
I added the following js code in red, in the #showConfirm section, after this.dialogTarget.classList.add(this.#config.activeClass)
var bootModal = new bootstrap.Modal(this.dialogTarget, {
keyboard: false
});
bootModal.show();
Thanks again,
From: Andy Cohen ***@***.***>
Sent: Monday, December 11, 2023 12:25 PM
To: RoleModel/turbo-confirm ***@***.***>
Cc: nrichardson1951 ***@***.***>; Mention ***@***.***>
Subject: Re: [RoleModel/turbo-confirm] Rails 7 -- RoleModel Turbo-Confirm error --"Uncaught TypeError: this.dialogTarget is null" (Discussion #16)
Yes, you'll need to define your own dialog styles, or use a style library like Bootstrap <https://getbootstrap.com/> , Bulma <https://bulma.io/> , or Optics <https://docs.optics.rolemodel.design/> . They will all provide a modal dialog component of some kind. If you're using a style library with a different active class for their modal component, you can pass that into RoleModelConfirm.init like RoleModelConfirm.init({activeClass: "custom-active-modal-class"})
—
Reply to this email directly, view it on GitHub <#16 (reply in thread)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/AUC22O2Q3VFFPXTK7WMK4CTYI46YTAVCNFSM6AAAAABAKBQJ76VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TQMRSGU2TC> .
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
@nrichardson1951 Thank you for your question! Do you have any elements on your page with the data attribute
id
? The way we have things setup internally, we have something like this: