How to use button

81 views
Skip to first unread message

Robin Ildefonso Ildefonso

unread,
Aug 22, 2024, 9:32:38 PM8/22/24
to str...@googlegroups.com
Hello, 
I am new in structr, 

I have my Schema 
image.png
And I check the REST API
i run this command 
image.png

I added a button that I want to use for this command 
fetch('/structr/rest/Project/info', {
method: 'POST',
credentials: 'include',
body: JSON.stringify({
name: "New Project"
}),
}).then(function(response) {
return response.json();
}).then(function(json) {
json.result.forEach(project => {
// process result
});
});

Here is the button 
image.png
Can you help me how to use the onclick or how to put the POST script? i tried to console.log it its working but when im trying to add the POST function its not working 

Kai Schwaiger

unread,
Aug 25, 2024, 1:09:17 AM8/25/24
to str...@googlegroups.com
Hello,

the “onclick" attribute simply outputs the given content into the onclick attribute in the HTML.
Outputting whole functions in there gets pretty messy pretty quick and will be hard to maintain later on,
so I would probably create a function “createProject” with your fetch call and put it in a script tag in the page
and simply put “javascript: createProject();” in the onclick attribute.

You could also add a HTML id to the button and keep the javascript completely encapsulated in the script tag (or file) and
look up the button by id and the attach a click listener with your code.

But all that is a lot of work to create basic functionality, if that is what you want and need then it is totally up to you, but there
is an easier way to achieve it. You should have a look at the “Events” tab for the button element.

With a configuration similar to the below screenshot you should be able to create the functionality without any javascript.

You only need to include the structr frontend javascript like so:
<script type="module" defer src="/structr/js/frontend/frontend.js"></script>

Hope that helps!

Best,
Kai

PastedGraphic-1.png


On 23. Aug 2024, at 03:32, Robin Ildefonso Ildefonso <ildefonso...@gmail.com> wrote:

Hello, 
I am new in structr, 

I have my Schema 
<image.png>
And I check the REST API
i run this command 
<image.png>

I added a button that I want to use for this command 
fetch('/structr/rest/Project/info', {
method: 'POST',
credentials: 'include',
body: JSON.stringify({
name: "New Project"
}),
}).then(function(response) {
return response.json();
}).then(function(json) {
json.result.forEach(project => {
// process result
});
});

Here is the button 
<image.png>
Can you help me how to use the onclick or how to put the POST script? i tried to console.log it its working but when im trying to add the POST function its not working 

--
You received this message because you are subscribed to the Google Groups "structr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structr+u...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/structr/CACXY51zkjdV%2BTebg5%2B8Vh60Rk4DDvVHWP05Gvb%3DGHviqy4Ltrg%40mail.gmail.com.

Robin Ildefonso Ildefonso

unread,
Aug 25, 2024, 1:22:52 AM8/25/24
to str...@googlegroups.com
Thank you for getting back to me so quickly.

I already solved the problem but can you please help me how to manage to edit the table? I already managed to Add and delete

image.png

If I set the data-structr-action in my td to Edit, I can see the save and cancel buttons but I can't update the fields, can you help me?

image.png

Here is the output, and also where can I put my code if I want to update it?

image.png

Kai Schwaiger

unread,
Aug 25, 2024, 3:35:45 AM8/25/24
to str...@googlegroups.com
The Edit Mode Binding Feature has been deprecated for a while and is removed in the newest snapshots and thus in the next major version 6.0.

The event mapping in the “Events” tab is the new place to do such things.

You can configure the edit behaviour like in the following screenshot. The outer tr has a repeater which lists all projects and makes the individual project available as “project”.

Hope that helps!
Kai


PastedGraphic-1.png


On 25. Aug 2024, at 07:22, Robin Ildefonso Ildefonso <ildefonso...@gmail.com> wrote:

Thank you for getting back to me so quickly.

I already solved the problem but can you please help me how to manage to edit the table? I already managed to Add and delete

<image.png>

If I set the data-structr-action in my td to Edit, I can see the save and cancel buttons but I can't update the fields, can you help me?

<image.png>

Here is the output, and also where can I put my code if I want to update it?

<image.png>

On Sun, 25 Aug 2024 at 13:09, 'Kai Schwaiger' via structr <str...@googlegroups.com> wrote:
Hello,

the “onclick" attribute simply outputs the given content into the onclick attribute in the HTML.
Outputting whole functions in there gets pretty messy pretty quick and will be hard to maintain later on,
so I would probably create a function “createProject” with your fetch call and put it in a script tag in the page
and simply put “javascript: createProject();” in the onclick attribute.

You could also add a HTML id to the button and keep the javascript completely encapsulated in the script tag (or file) and
look up the button by id and the attach a click listener with your code.

But all that is a lot of work to create basic functionality, if that is what you want and need then it is totally up to you, but there
is an easier way to achieve it. You should have a look at the “Events” tab for the button element.

With a configuration similar to the below screenshot you should be able to create the functionality without any javascript.

You only need to include the structr frontend javascript like so:
<script type="module" defer src="/structr/js/frontend/frontend.js"></script>

Hope that helps!

Best,
Kai

Robin Ildefonso Ildefonso

unread,
Aug 25, 2024, 9:17:29 AM8/25/24
to str...@googlegroups.com
I tried to replicate your image but the update is not working here is the screenshot 

image.png

I already dragged the Input to the Form input. here is my preview. Do i need to add function to my script? although it has a direct event in the data object?

image.png

Kai Schwaiger

unread,
Aug 26, 2024, 5:32:14 AM8/26/24
to str...@googlegroups.com
With that configuration you should not need to do anything manually in your own javascript. The only thing you need is the frontend library in that page:

<script type="module" defer src="/structr/js/frontend/frontend.js"></script>

Otherwise it is hard to tell why this does not work as expected. The repeater uses the data key “project”, as it is used here in ${project.id}, correct?

The “Add” and “Delete” work? Maybe the mixture of the deprecated “Edit Mode Binding” and the new “Event Action Mapping” does not work. It is really hard to diagnose...

I assume you are running version 5.2. You could try updating to the current snapshot version 6.0-SNAPSHOT



On 25. Aug 2024, at 15:17, Robin Ildefonso Ildefonso <ildefonso...@gmail.com> wrote:

I tried to replicate your image but the update is not working here is the screenshot 

<image.png>

I already dragged the Input to the Form input. here is my preview. Do i need to add function to my script? although it has a direct event in the data object?

<image.png>

On Sun, 25 Aug 2024 at 15:35, 'Kai Schwaiger' via structr <str...@googlegroups.com> wrote:
The Edit Mode Binding Feature has been deprecated for a while and is removed in the newest snapshots and thus in the next major version 6.0.

The event mapping in the “Events” tab is the new place to do such things.

You can configure the edit behaviour like in the following screenshot. The outer tr has a repeater which lists all projects and makes the individual project available as “project”.

Hope that helps!
Kai


Robin Ildefonso Ildefonso

unread,
Aug 26, 2024, 8:39:32 PM8/26/24
to structr
Hello, 

Yes, I followed the sample schema and data using the project convention. Upon checking my screenshot, and your screenshot has a difference.

I tried to update the docker from 5.0 to the latest but it is still pulling the 5.0 version

Screenshot 2024-08-27 at 8.27.22 AM.png

Screenshot 2024-08-27 at 8.35.50 AM.png

Screenshot 2024-08-27 at 8.36.38 AM.png

Kai Schwaiger

unread,
Aug 27, 2024, 11:13:08 AM8/27/24
to str...@googlegroups.com
I think you can try "structr/structr:5.2.0” for the latest stable version or you could go with "structr/structr:6.0-SNAPSHOT” for the most recent build.

In the 5.2.0 version there will still be a difference (the “dialog” feature has been added very recently) but it should work.
The 6.0-SNAPSHOT version should also work and have the most recent features.


On 27. Aug 2024, at 02:39, Robin Ildefonso Ildefonso <ildefonso...@gmail.com> wrote:

Hello, 

Yes, I followed the sample schema and data using the project convention. Upon checking my screenshot, and your screenshot has a difference.

I tried to update the docker from 5.0 to the latest but it is still pulling the 5.0 version

<Screenshot 2024-08-27 at 8.27.22 AM.png>

<Screenshot 2024-08-27 at 8.35.50 AM.png>

To view this discussion on the web, visit https://groups.google.com/d/msgid/structr/87f92299-3fec-4b1b-8836-0a59734e9d71n%40googlegroups.com.
<Screenshot 2024-08-27 at 8.27.22 AM.png><Screenshot 2024-08-27 at 8.36.38 AM.png><Screenshot 2024-08-27 at 8.35.50 AM.png>

Robin Ildefonso Ildefonso

unread,
Aug 27, 2024, 8:52:06 PM8/27/24
to structr
Thank you, I just skipped this because it's nice to have. 

I have another inquiry, I wasn't able to put it in a row like this 

Screenshot 2024-08-28 at 8.50.45 AM.png

\ The image below is my actual structr page. I update my existing div but it's returning like this. 


Screenshot 2024-08-28 at 8.50.02 AM.png

Robin Ildefonso Ildefonso

unread,
Aug 27, 2024, 10:57:04 PM8/27/24
to structr
Hi, please ignore my previous email.  Sorry 

I have a question sir, do you know if structr supports Carousel? In my demo my local carousel is working, when I imported it into Strucr the image did not automatically transform into another image.

Kai Schwaiger

unread,
Aug 28, 2024, 4:59:47 AM8/28/24
to str...@googlegroups.com
If the carousel works in your local demo then it should also work in structr. Usually carousels are javascript components, so if
the javascript files and images (+ possible css) are correctly imported into structr and are correctly included in the page it should work.


Robin Ildefonso Ildefonso

unread,
Aug 29, 2024, 7:32:16 PM8/29/24
to structr
Thank you, also can we get the elements of the HTML and put it in an example repeater?

Robin Ildefonso Ildefonso

unread,
Aug 29, 2024, 10:31:46 PM8/29/24
to structr
Hello, 

My apologies; please disregard my previous question. My inquiry is: can you share how to use widgets as shareable components and shareable data?

I'm trying to insert my data in Datagrid widgets. 

Thank you
Reply all
Reply to author
Forward
0 new messages