forked from avo-hq/avo
-
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.
Add the ability to clear the file input before form submit avo-hq#3164
- Loading branch information
1 parent
4a7798b
commit ff6070e
Showing
5 changed files
with
38 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.remove-icon { | ||
top: 5px; | ||
right: 5px; | ||
font-size: 18px; | ||
color: #ff0000; | ||
cursor: pointer; | ||
border-radius: 50%; | ||
padding: 2px 6px; | ||
z-index: 10; | ||
} |
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
16 changes: 16 additions & 0 deletions
16
app/javascript/js/controllers/fields/files_field_controller.js
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
|
||
export default class extends Controller { | ||
static targets = ["previewContainer", "removeIcon"]; | ||
|
||
preview() { | ||
this.removeIconTarget.style.display = "block"; | ||
} | ||
|
||
remove(event) { | ||
event.preventDefault(); | ||
const fileInput = this.previewContainerTarget.querySelector('input[type="file"]'); | ||
fileInput.value = ""; | ||
this.removeIconTarget.style.display = "none"; | ||
} | ||
} |