I've got a popup message with a close button at the top. If the user clicks the close button, they should never see the message again while on the site. If they don't click the close button, they will see it on the top of each page on the site.
When the user clicks the close button, I want to set request.session['promo'] to 0. On subsequent page loads on the site, if request.session['promo'] == 0, I will not show the popup message.
What is the best way of setting a session variable on click in django?
Thanks for the direction!
In HTML OnClick of button just call a function in views.py
Ex:
IN HTML :<Button onclick={% your_fucntion %}></button>
IN VIEWS.PY :
def your_fucntion(request):
request.session['promo'] == 'your_variable'
for getting variable :
promo = request.session['promo']
Related
I created a dynamic menu in oracle apex but the issue when click on any page after login
to the application again it redirect to login page first then open the page
this is the URL appear when click any page in the navigation menu
http://localhost:8080/ords/r/apex-system/login?session=11974340821162
this is the SQL query for dynamic menu :
select level ,
EN label,
'f?p=&APP_ID.:'||menu_seq||':'||':&SESSION.:::::' target,
EN as is_current,
ICON_IMAGE image_value
from SYSTEM_MENU
start with parent_m_id is null
connect by prior menu_id = parent_m_id
order siblings by menu_id
why always go to login page when click any page link on the navigation menu ?
Sounds like the session is getting reset when navigating to a menu item. At first glance (untested) I'd say there is a syntax error in the url. The session substitution string is in the wrong place. Try replacing ':&SESSION.:::::' with '&SESSION.:::::'.
But... why bother constructing the application url yourself when you can have a function APEX_PAGE.GET_URL do it for you ?
select level ,
EN label,
APEX_PAGE.GET_URL (p_page => 'menu_seq') target,
EN as is_current,
ICON_IMAGE image_value
from SYSTEM_MENU
start with parent_m_id is null
connect by prior menu_id = parent_m_id
order siblings by menu_id
Need your suggestions on handling the validation without submitting page in APEX 5.0. I have following items on my apex report page.
"Select list" item which contains some static values
date pickers ( start date and end date)
Submit button ( Once submit is clicked the report date is displayed )
Here I need to add a dynamic action or validation to the submit button so that if user clicks the submit button without selecting a value from the "Select List", an error message should be displayed to the user that he needs to select the item first from the "Select list" page item. With out any selection from the list , the processing should stop and a warning message should be displayed ( either it could be popup message or message can be marked on the select list page item ) .Point to be noted here that during the submit I do not want to refresh the page, just would like a quick error message to display.
Appreciate your help.
in a similar case i used dynamic actions
dynamic actions works on client side
in my case i am not enabling submit button until user changes the select list value
in my dynamic action my config is as below
Event=change
selection=items
item=selectlistID
and true action is
action=disable
button=submitbuttonname
in your case you can choose javascript as action and add your javascript code
I am trying to solve an issue with modals. What I want to do is allow the user to click the browser's back button to dismiss a modal and return to the original state of the page, this is: without modal. For such purpose I thought about using HTML 5 history API.
I started trying to append a querystring parameter to the URL, such as http://...page.html?show_modal=[yes|no] but I ended leaving this approach because I couldn't handle all the stuff involving popstate event, pageshow event, etc. I couldn't make it work and it overwhelmed me.
Then I tried with a more simple approach involving a hash appended to the URL, such as http://...page.html#modal, and the hashchange event. This approach is working better for me and I almost have it.
When the user clicks the button to show the modal, he or she can click the browser's back button and it will dismiss the modal. Furthermore, after that, the user can click the browser's forward button and it will show the modal again. Very nice! The user can also navigate directly to the URL with the hash to access directly this state of the page, as well as he or she can bookmark such state of the page. It's working pretty neat and I'm rather happy with the results.
The problem is that it is not working totally perfect. When the user dismiss the modal by clicking the background, the ESC key or the X in the upper right corner, the history starts to mess up. Try it: open the modal by clicking on the button, then click the background to dismiss it (look a the URL in the address bar, first problem here is that the hash isn't removed), then click your browser back button and you will see it isn't working correctly. You will end with a duplicate in your history and you have to click the back button twice in order to go to the previous page. This is not desirable from an UX viewpoint. Does anyone know a solution to this?
I provide my code in this CodePen and at the end of this question. I suggest trying it in your own machine and NOT IN Codepen, so you can view the hash in the URL, etc. Also, it doesn't work in Codepen Full mode, I don't know why.
Thanks!!
I am using Foundation 5.2.1
HTML
<div class="row">
<div class="small-12 columns">
<h1>Reveal Modal</h1>
<h2>Manipulation of the browser history for a better UX</h2>
<a class="button radius" href="#" data-reveal-id="sampleModal" id="button">Show Modal...</a>
</div>
</div>
<!-- ############# -->
<!-- MODAL -->
<!-- ############# -->
<div id="sampleModal" class="reveal-modal medium" data-reveal>
<h2>Hi!</h2>
<p>You may think you are on a new page now, but you aren't. Try to click your browser <kbd>Back</kbd> button to dismiss this modal and return to the the page you were viewing.</p>
<a class="close-reveal-modal">×</a>
</div>
JavaScript
function setModalHash(url, present) {
var a = $('<a>', { href:url } )[0]; // http://tutorialzine.com/2013/07/quick-tip-parse-urls/
var newHash = "";
if (present === true) {
newHash = "#modal";
}
// Build the resulting URL
result = a.protocol + "//" + a.hostname + ":" + a.port + a.pathname + a.search + newHash;
return result;
}
$("#button").on('click', function() {
history.pushState(null, null, setModalHash(document.URL, true));
});
$(window).on("hashchange load",function(e) {
// Handling also the load event allows navigation directly to http://host/path/to/file#modal and bookmarking it
if (document.location.hash == "#modal") {
$("#sampleModal").foundation("reveal","open");
}
else {
$("#sampleModal").foundation("reveal","close");
}
});
I've been messing with the history api/History.js in combination with session storage to maintain modal state, and open/close based upon user navigation. I've finally achieved about 90% of my goal, but history is implemented very poorly in Safari and iOS Safari so remove the features for these browsers.
Some of the problems you may be running into with the hash approach is that when you use the # with pushstate it actually doesn't push a new object into the history state. It sometimes seems to push history onto the stack and you could use history.back() to fire a popstate, but if you were to say refresh the page with your hashurl and do some sort of check for hash on page initiation, there doesn't seem to be a new history pushed onto the stack, and therefore on backwards navigation the user will leave the site rather than closing the modal.
Here is my implementation working for all browsers except for where it falls back to normal behavior is Safari:
http://dtothefp.github.io/hosted_modal_history_sample/
https://github.com/dtothefp/html5history_express_modal_toggle
Like I said I use History.js in combination with sessionstorage because annoyingly enough, in the popstate for closing the modal the history object is removed, which is exactly when I would need it. In all a very poorly implemented API.
I don't change the URL because this project does not have a backend, so if I change the URL with no hash, on page refresh the page would not be found. An alternate implementation would be a query string, which will properly update history when used in the pushstate, but ends up being bad UX because if the user closes the modal not using the backwards navigation (i.e. hitting the cancel button or clicking off), removing the query string would result in a page refresh.
I have a page with one field only. How can user submit the page by pressing 'Enter' without having to click the 'Submit' button? User should therefore be able to either press 'Enter' or click 'Submit'. Thank you.
APEX text items have a property "Submit when Enter pressed". Set this to Yes and you are almost done. The APEX request is set to the name of the item so that you can, if you need to, have submit processing that depends on this e.g. PL/SQL Condition:
:request in ('SUBMIT','P1_MY_TEXT_ITEM')
What is your APEX version ?
If you are using APEX 4, you can try this JQuery code :
$('#YOUR_TEXTFIELD_ID').keyup(function(e) {
if (e.keyCode == '13')
$('#YOUR_BUTTON').trigger('click');
});
It works only if any onclick event has been defined for the button, else simply call apex.submit(...) instead.
Working with APEX 3.2:
I want to show a confirmation popup on Page 2 when Page 1 has successfully been submitted.
Right now I can get the text from the 'Process Success Message' to appear on Page 2, but instead of the 'Process Success Message' text, I want an alert popup. Any idea how to do that?
NOTE: I don't want to put javascript on the 'Submit' button of Page 1, because if there is a validation error, the alert popup will appear anyway every time the 'Submit' button is clicked. I just want the popup to appear only if Page 1 has successfully submitted.
You could do this:
1) Edit the page template used by Page 2. Edit the Success Message subtemplate and put a span tag around the #SUCCESS_MESSAGE# placeholder like this:
<span id="successMessage">#SUCCESS_MESSAGE#</span>
2) Create some Javascript on Page 2 to run when the page is loaded that does this:
if ($x('successMessage')) alert ($x('successMessage').innerHTML);
The Success Message is only rendered if there is a success message to display, and so the alert will only happen when there is a success message to display also.
3) You could suppress the display of the success message on the page itself if you want by adding style="display:none" to the outer div of the Success Message subtemplate.
NB The template change will affect all pages that are based on it, not just Page 2, so you may need to take a copy of it first. You could include the Javascript in the page template so that you don't need to keep adding the same on load Javascript to each page.