Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flash fixture documentation is incorrect #912

Closed
kszys opened this issue Aug 21, 2024 · 7 comments
Closed

Flash fixture documentation is incorrect #912

kszys opened this issue Aug 21, 2024 · 7 comments

Comments

@kszys
Copy link
Contributor

kszys commented Aug 21, 2024

It seems that the documentation for the Flash fixture is lagging behind the actual code...

The documentation (https://py4web.com/_documentation/static/en/chapter-06.html#the-flash-fixture) gives an example that generally does not seem to work with the current version of utils.js.

It suggests setting up a <div id="py4web-flash"></div> while the script seems to be looking for something with id="alerts-flash". Also there does not seem to be a utils.flash() function that I could actually find...

It would be useful to update the documentation to match the code.

@andreaschizzali
Copy link

I also noticed some issues with the documentation of the Flash fixture, but ist is not clear to me where exactly are the causes.
The function utils.flash(), seems to me, will be built after loading the sctipt utils.js.
Towards the end of utils.js there is the line
Q.handle_flash();
if a flash request was found (elem), this function defines Q.flash:
Q.flash = function(detail) {elem.dispatchEvent(new CustomEvent('flash', {detail: detail}));};
then this function is evaluated and i think an event 'flash' is defined. Possibly utils.flash executes the event. I'm not shure about, my knowledge of js is limited.
I also noticed, that the two flash examples in showcase are working.
In flash.example.html the template uses Q.flash(). The generic template layout.html uses a custom element flash_alerts (not alerts-flash) with a data-Attribute data-alert.
There are two diffrent mechanisms, only in case of a redirect the flash is stored in the cookie.
Lately I was in vacation, so I did not complete my analisys of the issue. I also found other ways to get my flash messages, even if not in the canonical way. I tried something, but did not succed with the methods of the examples in showcase, when the actions are a little different.
Perheaps someone more experienced has a clue.

@kszys
Copy link
Contributor Author

kszys commented Aug 23, 2024 via email

@mdipierro
Copy link
Contributor

mdipierro commented Aug 23, 2024 via email

mbelletti added a commit to mbelletti/py4web that referenced this issue Aug 23, 2024
Updated fash fixture doc to actual behavior as web2py#912
@andreaschizzali
Copy link

Thank you,
the proposed modification of the documentation is fine, but solves only the server side flash. For client side flash messages, the documentation suggests to call
utils.flash({'message': 'hello world', 'class': 'info'});
but I was not able to get it working. I tried in the template for an action with a simple
<button onclick="utils.flash({'message': 'you clicked the button', 'class':'success'})">Click me</button>
but has no reaction.
I tried with
<button onclick="Q.flash({message: 'Q: you clicked the button', class:'success'})">Q.Click me</button>
and this works.
It could be that I had to use the call to utils.flash() in a different way, but the documentation does not explain how.

@mbelletti
Copy link
Contributor

Updated docs including working js example: #914

@andreaschizzali
Copy link

The example works for me only for server flash messages.
I was not able to get client flash messages with the proposed
utils.flash({'message': 'you clicked the button', 'class':'success'})
instead I had correct results using Q.flash(... as in the (working) example in showcase for flash_example_naive.py using examples/flash_example.html that contains

[[extend 'layout.html']]

<button onclick="Q.flash({message: 'you clicked the button', class:'warning'})">Click me</button>
<br/>or type something below<br/>
<input onchange="Q.flash({message: this.value, class: 'success'});this.value='';"/>

there is no trace of an util.flash(...
I think that most probably either the documentation or the flash_example need a correction.

mdipierro pushed a commit that referenced this issue Aug 27, 2024
* Update Flash Fixture doc

Updated fash fixture doc to actual behavior as #912

* Flash fixtures docs

Working example from python and js
@mdipierro
Copy link
Contributor

Thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants