Skip to content

Commit 51b30e0

Browse files
committed
Revert Stimulus changes back to master version
The Stimulus validation logic and form event handlers were not the issue. Reverting to exact master code to isolate the SWC transpilation problem.
1 parent cd5ff7e commit 51b30e0

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

app/views/comments/turbo/_horizontal_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<hr />
66

7-
<%= form_with(model: @comment, data: { action: "submit->comments#resetText" }, class: "form-horizontal flex flex-col gap-4") do |f| %>
7+
<%= form_with(model: @comment, data: { action: "turbo:submit-end->comments#resetText" }, class: "form-horizontal flex flex-col gap-4") do |f| %>
88
<div class="form-group flex flex-col gap-0 items-center lg:gap-4 lg:flex-row">
99
<%= f.label "Name", class: "w-full lg:w-2/12 lg:text-end shrink-0" %>
1010
<%= f.text_field :author, data: { comments_target: "commentAuthor" }, class: "px-3 py-1 leading-4 border border-gray-300 rounded w-full", placeholder: "Your Name" %>

app/views/comments/turbo/_inline_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<hr />
66

7-
<%= form_with(model: @comment, data: { action: "submit->comments#resetText" }, class: "form-inline flex flex-col lg:flex-row flex-wrap gap-4") do |f| %>
7+
<%= form_with(model: @comment, data: { action: "turbo:submit-end->comments#resetText" }, class: "form-inline flex flex-col lg:flex-row flex-wrap gap-4") do |f| %>
88
<div class="flex gap-2 items-center">
99
<%= f.label "Name", class: "form-label mr-15" %>
1010
<%= f.text_field :author, data: { comments_target: "commentAuthor" }, class: "px-3 py-1 leading-4 border border-gray-300 rounded", placeholder: "Your Name" %>

app/views/comments/turbo/_stacked_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<hr />
66

7-
<%= form_with(model: @comment, data: { action: "submit->comments#resetText" }, class: "flex flex-col gap-4") do |f| %>
7+
<%= form_with(model: @comment, data: { action: "turbo:submit-end->comments#resetText" }, class: "flex flex-col gap-4") do |f| %>
88
<div class="flex flex-col gap-0">
99
<%= f.label "Name", class: "w-full" %>
1010
<%= f.text_field :author, data: { comments_target: "commentAuthor" }, class: "px-3 py-1 leading-4 border border-gray-300 rounded w-full", placeholder: "Your Name" %>

client/app/controllers/comments_controller.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,34 @@ marked.use(mangle());
1010
export default class extends Controller {
1111
static targets = ['commentList', 'commentAuthor', 'commentText', 'commentRefresh', 'alertDiv', 'errorList'];
1212

13-
resetText(event) {
13+
resetText() {
1414
const inputAuthor = this.commentAuthorTarget;
1515
const inputText = this.commentTextTarget;
1616
const alertDiv = this.alertDivTarget;
1717
const errorList = this.errorListTarget;
1818

1919
const errors = [];
2020

21-
// Clear previous errors
22-
errorList.innerHTML = '';
23-
alertDiv.classList.add('hidden');
24-
2521
if (!inputAuthor.value || !inputText.value) {
26-
// Prevent form submission if validation fails
27-
event.preventDefault();
28-
22+
errorList.innerHTML = '';
2923
if (!inputAuthor.value) {
3024
errors.push('Author');
31-
}
32-
if (!inputText.value) {
25+
} else if (!inputText.value) {
26+
errors.push('Text');
27+
} else {
28+
errors.push('Author');
3329
errors.push('Text');
3430
}
3531
errors.forEach((error) => {
3632
const errorString = `<li>${error}: can't be blank</li>`;
3733
errorList.insertAdjacentHTML('afterbegin', errorString);
3834
});
3935
alertDiv.classList.remove('hidden');
36+
} else {
37+
alertDiv.classList.add('hidden');
38+
errorList.innerHTML = '';
39+
inputText.value = '';
40+
this.refreshCommentList();
4041
}
4142
}
4243

0 commit comments

Comments
 (0)