Skip to content

Commit

Permalink
preserving file inputs ok
Browse files Browse the repository at this point in the history
  • Loading branch information
librasteve committed Sep 8, 2024
1 parent 8240672 commit f06ebf5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
4 changes: 2 additions & 2 deletions META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
"Routes::Examples::Value-Select": "lib/Routes/Examples/Value-Select.rakumod",
"Routes::Examples::Animations": "lib/Routes/Examples/Animations.rakumod",
"Routes::Examples::File-Upload": "lib/Routes/Examples/File-Upload.rakumod",
"Routes::Examples::Preserving-File-Inputs": "lib/Routes/Examples/Preserving-File-Inputs.rakumod",
"Routes::Examples::Dialogs-Browser": "lib/Routes/Examples/Dialogs-Browser.rakumod",
"Routes::Examples::Dialogs-UIKit": "lib/Routes/Examples/Dialogs-UIKit.rakumod",
"Routes::Examples::Dialogs-Bootstrap": "lib/Routes/Examples/Dialogs-Bootstrap.rakumod",
"Routes::Examples::Dialogs-Custom": "lib/Routes/Examples/Dialogs-Custom.rakumod",
"Routes::Examples::Dialogs-Pico": "lib/Routes/Examples/Dialogs-Pico.rakumod",
"Routes::Examples::Tabs-Hateoas": "lib/Routes/Examples/Tabs-Hateoas.rakumod",
"Routes::Examples::Tabs-Hyperscript": "lib/Routes/Examples/Tabs-Hyperscript.rakumod"

"Routes::Examples::Tabs-Hyperscript": "lib/Routes/Examples/Tabs-Hyperscript.rakumod",
},
"resources": [
],
Expand Down
3 changes: 3 additions & 0 deletions lib/Routes.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ sub routes() is export {
use Routes::Examples::File-Upload;
include file_upload => file_upload-routes;

use Routes::Examples::Preserving-File-Inputs;
include preserving_file_inputs => preserving_file_inputs-routes;

use Routes::Examples::Dialogs-Browser;
include dialogs_browser => dialogs_browser-routes;

Expand Down
31 changes: 31 additions & 0 deletions lib/Routes/Examples/Preserving-File-Inputs.rakumod
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use Cro::HTTP::Router;
use Cro::WebApp::Template;

sub preserving_file_inputs-routes() is export {

my $upload-dir = "$*HOME/Downloads/uploads/";

unless $upload-dir.IO.e {
$upload-dir.IO.mkdir or die "Failed to create upload directory: $!";
}

route {
template-location 'templates/preserving_file_inputs';

get -> {
template 'index.crotmp';
}

post -> 'upload' {
content 'text/html', "Uploaded!";
}
}
}

#@bp.route("/")
#def index():
# return render_template("preserving_file_inputs/index.html.j2")
#
#@bp.route("/upload", methods=("POST",))
#def upload_hyperscript():
# return "Uploaded!"
13 changes: 13 additions & 0 deletions templates/preserving_file_inputs/index.crotmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h3>Before</h3>
<form id="binaryFormBefore" enctype="multipart/form-data" hx-post='/preserving_file_inputs/upload' hx-swap="outerHTML"
hx-target="#binaryFormBefore">
<input type="file" name="binaryFile"><br>
<button type="submit">Submit</button>
</form>

<h3>After</h3>
<input form="binaryFormAfter" type="file" name="binaryFile">
<form id="binaryFormAfter" enctype="multipart/form-data" hx-post='/preserving_file_inputs/upload' hx-swap="outerHTML"
hx-target="this">
<button type="submit">Submit</button>
</form>

0 comments on commit f06ebf5

Please sign in to comment.