-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Trestle 0.9.9] Custom post/patch action in a dialog form does not update the form in place #466
Comments
I'm able to reproduce this behavior (both the old that's working and the new that's not). Thank you for the clear reproduction example. At this stage, I can't see why 0.8.13 works and 0.9.9 doesn't, as most of the form and dialog code is fairly similar between those versions. I'm more surprised that this does work in 0.8.13 -- you don't have any custom JS handling the My only other thought is that it's maybe a change in behavior between jquery-ujs (used in 0.8.x) and rails-ujs (used in 0.9.x) but nothing is jumping out at me there either. |
Thank you for your quick reply ! As it stands i have no relevant extra custom JS on top of Trestle :/ My only solution here seems to be to remove the dialog behavior altogether from the forms with custom actions |
@spohlenz do you think you'll have some time to investigate further into the regression ? :) |
I'd definitely like to at least understand why this is happening (and hopefully find a workaround for you). I'll aim to investigate further over the next few days. Having said that, the majority of my focus is on the new 0.10.0 release which has Turbo & Stimulus built-in, and should hopefully make these types of updates much easier. If you feel inclined, you may wish to experiment with 0.10.0.pre. I'm aiming to put together some examples of exactly these types of non-standard updates using Turbo and the Stimulus controllers built in to Trestle 0.10.0. |
@spohlenz thanks for your quick reply, and the investigation :) If you happen to find a way to work around that problem with 0.9.9, i'd be happy to hear it ! In the meantime i will also try to update to 0.10.0.pre and see if i have a more satisfactory dialog behavior |
I've been able to identify the line of code causing the difference in behavior: Your data-remote link within the form triggers the If you'd like to do something similar in 0.9.x, you can add the following code to Trestle.init(function (root) {
$(root).find('[data-behavior="update-dialog"]')
.on('ajax:send', function (e) {
$(this).addClass('loading');
})
.on('ajax:complete', function (e) {
var xhr = e.detail[0];
$(this).removeClass('loading');
var contentType = (xhr.getResponseHeader('Content-Type') || '').split(';')[0];
if (contentType === 'text/html') {
if (/<html/i.test(xhr.responseText)) {
// Response is a full HTML page, likely an error page. Render within an iframe.
var $context = $(this).closest('[data-context]');
var iframe = $('<iframe>').addClass('error-iframe').get(0);
$context.html(iframe);
iframe.contentWindow.document.documentElement.innerHTML = xhr.responseText;
} else {
// Find the parent context and replace content
var $context = $(this).closest('[data-context]');
$context.html(xhr.responseText);
// Initialize replaced elements within the context
Trestle.triggerInit($context);
// Focus the correct tab
Trestle.focusActiveTab();
}
} else if (contentType === 'text/plain') {
// Assume an error response
const title = xhr.status + '(' + xhr.statusText + ')';
Trestle.Dialog.showError(title, xhr.responseText);
}
});
}); and add I'll update this thread tomorrow with an example of how to do this in 0.10.0. |
Hello again @spohlenz , It might even be worth it to implement it as a feature in 0.10.0 ? Thanks again and have a great day :) |
Hello everyone,
I'm on a Rails 6 project (Ruby 2.6.5), with Trestle now updated to 0.9.9 (from 0.8.13), Trestle-search 0.4.3 and Trestle-auth 0.4.4
I'm testing with Chrome 126.0.6478.62
I have a User model and am using Trestle to let an admin create/update users.
In the form, which has the
dialog: true
option, i have alink_to
link withremote: true
that performs acustom_action
defined inUsersAdmin
.When i click on this link :
This only happens for extra links in the form calling custom actions, the basic form submission works perfectly with dialogs. I've taken a look at the Trestle code, and i found the code that replaces the dialog content on form submission (in form.js), but I can't explain why the working behavior of 0.8.13 is not working anymore for me on 0.9.9 .
Without the context of a dialog form, removing the
remote: true
from the link makes everything work with no dialog. However i wish to use a dialog in this scenario.To reproduce, simply use a standard Trestle admin, create a record for it, and add these peaces of code :
Are you able to reproduce this ? If so, do you know how to update the dialog after a remote custom_action ?
Thank you for your help !
The text was updated successfully, but these errors were encountered: