input value example
This commit is contained in:
parent
b96faacf89
commit
3a45e25409
4 changed files with 36 additions and 1 deletions
17
examples/InputValueExample/main.cpp
Normal file
17
examples/InputValueExample/main.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import Crafter.CppDOM;
|
||||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
|
||||
HtmlElement* body = new HtmlElement("body", R"(<h1>Input GetValue() and SetValue() Example</h1><br><input id="input" type="text" placeholder="Enter your text here..."><br><button id="button">Change Value</button><p id ="valueOutput"></p>)");
|
||||
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("");
|
||||
});
|
||||
}
|
||||
17
examples/InputValueExample/project.json
Normal file
17
examples/InputValueExample/project.json
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "main",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "executable",
|
||||
"implementations": ["main"],
|
||||
"target": "wasm32-wasi",
|
||||
"debug" : true,
|
||||
"dependencies": [
|
||||
{
|
||||
"path":"../../project.json",
|
||||
"configuration":"lib-debug"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
1
examples/InputValueExample/run.sh
Executable file
1
examples/InputValueExample/run.sh
Executable file
|
|
@ -0,0 +1 @@
|
|||
caddy file-server --listen :8080 --root bin/executable
|
||||
|
|
@ -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<char*>(value));
|
||||
return result;
|
||||
} else {
|
||||
return "";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue