-
-
Notifications
You must be signed in to change notification settings - Fork 45
Fixes duplicate form while replying to Comment #267
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
Open
rohnsha0
wants to merge
3
commits into
main
Choose a base branch
from
rohnsha0/issue#88
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+164
−5
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixed mishandling of dynamic form label updates - New Comment & Thread @rohnsha0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -288,9 +288,18 @@ | |
|
|
||
| <fieldset> | ||
|
|
||
| <legend i18n:translate="label_add_comment">Add comment</legend> | ||
|
|
||
| <p tal:content="view/comment_transform_message"> | ||
| <legend class="comment-form-legend" | ||
| data-new-comment-text="Add a new comment" | ||
| data-reply-text="Reply here (this thread)" | ||
| i18n:translate="label_add_comment" | ||
| >Add a new comment</legend> | ||
|
|
||
| <p class="comment-form-description" | ||
| tal:content="view/comment_transform_message" | ||
| tal:attributes=" | ||
| data-reply-html view/get_reply_transform_message; | ||
| " | ||
| > | ||
| You can add a comment by filling out the form below. Plain text | ||
| formatting. | ||
| </p> | ||
|
|
@@ -299,5 +308,76 @@ | |
|
|
||
| </fieldset> | ||
| </div> | ||
|
|
||
| <!-- JavaScript to handle dynamic form label updates --> | ||
| <script type="text/javascript"> | ||
| (function() { | ||
| 'use strict'; | ||
|
|
||
| // Cache selectors for better performance | ||
| var REPLY_FORM_SELECTOR = '.reply'; | ||
| var LEGEND_SELECTOR = '.comment-form-legend'; | ||
| var DESCRIPTION_SELECTOR = '.comment-form-description'; | ||
| var IN_REPLY_TO_SELECTOR = 'input[name*="in_reply_to"]'; | ||
|
|
||
| // Update form labels for reply forms | ||
| function updateFormLabels(form) { | ||
| var legend = form.querySelector(LEGEND_SELECTOR); | ||
| var description = form.querySelector(DESCRIPTION_SELECTOR); | ||
| var inReplyToField = form.querySelector(IN_REPLY_TO_SELECTOR); | ||
| var isReply = inReplyToField && inReplyToField.value; | ||
|
|
||
| if (legend) { | ||
| legend.textContent = isReply && legend.dataset.replyText ? | ||
| legend.dataset.replyText : | ||
| legend.dataset.newCommentText || legend.textContent; | ||
| } | ||
|
|
||
| if (description) { | ||
| description.innerHTML = isReply && description.dataset.replyHtml ? | ||
| description.dataset.replyHtml : | ||
| description.textContent.trim(); | ||
| } | ||
| } | ||
|
|
||
| // Process all reply forms | ||
| function processReplyForms() { | ||
| document.querySelectorAll(REPLY_FORM_SELECTOR).forEach(updateFormLabels); | ||
| } | ||
|
|
||
| // Initialize observer for dynamically added forms | ||
| function initObserver() { | ||
| var observer = new MutationObserver(function(mutations) { | ||
| mutations.forEach(function(mutation) { | ||
| mutation.addedNodes.forEach(function(node) { | ||
| if (node.nodeType === Node.ELEMENT_NODE) { | ||
| // Check if this node is or contains a reply form | ||
| var forms = node.matches && node.matches(REPLY_FORM_SELECTOR) ? | ||
| [node] : | ||
| (node.querySelectorAll ? Array.from(node.querySelectorAll(REPLY_FORM_SELECTOR)) : []); | ||
|
|
||
| forms.forEach(updateFormLabels); | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| observer.observe(document.body, { childList: true, subtree: true }); | ||
| } | ||
|
|
||
| // Initialize when DOM is ready | ||
| function init() { | ||
| processReplyForms(); | ||
| initObserver(); | ||
| } | ||
|
|
||
| if (document.readyState === 'loading') { | ||
| document.addEventListener('DOMContentLoaded', init); | ||
| } else { | ||
| init(); | ||
| } | ||
| })(); | ||
| </script> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sounds like a perfect task for |
||
|
|
||
| </div> | ||
| </tal:block> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should update the code in https://github.com/plone/mockup/blob/master/src/pat/controlpanels/discussion-comments--implementation.js (then release it in plone.staticresources), not add a script to every page that uses comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davisagli I am unable to test out changes made in
mockuprepo locally usingbuildout.coredev... I have already implemented some fix but unable to test it outIs there some other docs to test the changes?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rohnsha0 I am not up to date on the current processes for developing javascript for Classic UI, since I'm only working on Volto sites these days.
There is some information in https://github.com/plone/plone.staticresources?tab=readme-ov-file#how-to-upgrade-the-resources-in-this-package (which is where the mockup scripts are built and released to be used in Plone) and in https://github.com/plone/mockup?tab=readme-ov-file#development
If you have questions maybe @thet or @petschki can help, or ask in the Classic UI channel on Discord.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rohnsha0 to test local mockup changes please check out the
Developmentsection of the readme: https://github.com/plone/mockup?tab=readme-ov-file#development ... feel free to contact me on discord if you need help.