From 3a45e25409f4c9d7e6939eee6d31f70a1f84a677 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Wed, 12 Nov 2025 16:36:52 +0100 Subject: [PATCH] input value example --- examples/InputValueExample/main.cpp | 17 +++++++++++++++++ examples/InputValueExample/project.json | 17 +++++++++++++++++ examples/InputValueExample/run.sh | 1 + implementations/Crafter.CppDOM-HtmlElement.cpp | 2 +- 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 examples/InputValueExample/main.cpp create mode 100644 examples/InputValueExample/project.json create mode 100755 examples/InputValueExample/run.sh diff --git a/examples/InputValueExample/main.cpp b/examples/InputValueExample/main.cpp new file mode 100644 index 0000000..247199a --- /dev/null +++ b/examples/InputValueExample/main.cpp @@ -0,0 +1,17 @@ +import Crafter.CppDOM; +import std; +using namespace Crafter; + + +HtmlElement* body = new HtmlElement("body", R"(

Input GetValue() and SetValue() Example



)"); +HtmlElement* button = new HtmlElement("button"); +HtmlElement* output = new HtmlElement("valueOutput"); +HtmlElement* input = new HtmlElement("input"); + +int main(){ + button->AddClickListener([](Crafter::MouseEvent) { + std::string newValue = input->GetValue(); + output->SetInnerHTML(newValue); + input->SetValue(""); + }); +} \ No newline at end of file diff --git a/examples/InputValueExample/project.json b/examples/InputValueExample/project.json new file mode 100644 index 0000000..9750e20 --- /dev/null +++ b/examples/InputValueExample/project.json @@ -0,0 +1,17 @@ +{ + "name": "main", + "configurations": [ + { + "name": "executable", + "implementations": ["main"], + "target": "wasm32-wasi", + "debug" : true, + "dependencies": [ + { + "path":"../../project.json", + "configuration":"lib-debug" + } + ] + } + ] +} \ No newline at end of file diff --git a/examples/InputValueExample/run.sh b/examples/InputValueExample/run.sh new file mode 100755 index 0000000..e706621 --- /dev/null +++ b/examples/InputValueExample/run.sh @@ -0,0 +1 @@ +caddy file-server --listen :8080 --root bin/executable \ No newline at end of file diff --git a/implementations/Crafter.CppDOM-HtmlElement.cpp b/implementations/Crafter.CppDOM-HtmlElement.cpp index e8e98ec..c43c678 100644 --- a/implementations/Crafter.CppDOM-HtmlElement.cpp +++ b/implementations/Crafter.CppDOM-HtmlElement.cpp @@ -66,7 +66,7 @@ namespace Crafter { const char* value = CppDOMBindings::GetValue(ptr); if(value != nullptr) { std::string result(value); - std::free(value); + std::free(const_cast(value)); return result; } else { return "";