-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from leouofa/turbo-upgrade
Updating the form submission state
- Loading branch information
Showing
5 changed files
with
22 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,13 +1,25 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
|
||
export default class extends Controller { | ||
static targets = ["button"] | ||
static targets = ["button", "textarea"] | ||
|
||
connect() { | ||
// Only call toggleButtonState if textareaTarget is present | ||
if (this.hasTextareaTarget) { | ||
this.toggleButtonState() | ||
} | ||
} | ||
|
||
toggleButtonState() { | ||
const message = this.textareaTarget.value.trim() | ||
this.buttonTarget.disabled = message.length === 0 | ||
} | ||
|
||
onInput() { | ||
this.toggleButtonState() | ||
} | ||
|
||
submit(e) { | ||
this.buttonTarget.classList.add('loading') | ||
this.buttonTarget.disabled = true | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
= form_with url: iterate_writing_style_path(parent), class: 'ui reply form !mb-20', method: :post, local: true do |form| | ||
= form_with url: iterate_writing_style_path(parent), data: {'controller': 'form'}, class: 'ui reply form !mb-20', method: :post, local: true do |form| | ||
.field | ||
= form.text_area :message, rows: 3, placeholder: 'Instructions. I.e. "Remove Lines 10 and 11"', id: 'form_text_area' | ||
= form.text_area :message, rows: 3, placeholder: 'Instructions. I.e. "Remove Lines 10 and 11"', id: 'form_text_area', data: {'form-target': 'textarea', 'action': 'input->form#onInput'} | ||
.actions | ||
= form.submit 'Iterate On Prompt', class: 'btn-primary' | ||
= form.submit 'Iterate On Prompt', class: 'btn-primary', data: {'form-target': 'button'} |
This file contains 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
This file contains 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