Automatically open a popup on load with MVC - asp.net-mvc

I have a page with ASP.net MVC 5 with Bootstrap in that displays a table of many records. I have a popup that open when I click on a button that is located on each row, basically some CRUD. This works fine.
What I would like to do now is when a user enter a specific URL (like site/Proof/LoadSpecific/342) to open the page as usual, but also show the modal as if I clicked on a specific button.
I am faily new to MVC, JQuery and web in general. How would I do this ?
Thanks

If you're using bootstrap modals you can use the following functions (assuming you have the bootstrap js and jquery scripts included as well)
assuming myModal is the id of your modal element:
$('#myModal').modal('toggle'); //toggles the shown/hidden state of the modal
$('#myModal').modal('show'); //shows the modal
$('#myModal').modal('hide'); //hides the modal
so you would include a script on your page that shows the bootstrap modal on load such as the following:
$(function() {
$('#myModal').modal('show');
});
Here's a link to the bootstrap 3.3 documentation which has a good deal more information on these components and how you can use them.

Related

Rails 6/Hotwire - how force "full page load" when link_to a certain page

I'm using a Rails 6 template (Jumpstart Pro) that has the new stuff hotwire, stimulus, webpacker. It works OK for basic stuff... scaffolding new models and make CRUD forms, etc.
However one of my pages uses a vendor's javascript widget, which also requires jquery.
Neither Jumpstart Pro template nor its Forum have any up-to-date documentation or support for adding jQuery via webpacker (e.g., no support for adding jquery the "right way").
So I've added jquery to the one page that needs it via a good old fashioned script tags in the header
%script{:src => "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"}
followed by the vendor's javascript to initialize the vendor's widget, inside $(document).ready(function(){ init_code_goes_here }); so the widget has time to load to the page.
Works: If I type the page's url into the browser "localhost:5000/cool_page" or "mydev.ngrok/cool_page", it works fine.
Broken: But clicking a link IN the app to go to the page (via link_to "cool page", "/cool_page") does not work:
jQuery is loaded (I have a little "hello world" jquery script that un-hides a div to confirm jquery is loaded)
the vendor widget does not load properly (browser console says widget object is null)
But if I then refresh the page, everything loads fine.
So the page works if "loaded" but not it reached via another page.
From this I infer that the magic behind hotwire/etc is interfering with a proper load of the page when I navigate to it.
So, the question: in a hotwire-enabled Rails 6 app, is there any way to have a nav link that, when clicked, simply tells Rails... skip hotwire shortcuts, load this page for real?
I believe your issue is just that you need to restore default (non-Hotwire) link behavior. There are 3 ways to do that.
See this answer: https://stackoverflow.com/a/68657223/2648054
In short:
1: Set the data-turbo attribute to false.
2: Set the target attribute to "_top".
3: Move the link outside any Turbo frame. Any link inside a Turbo frame, without one of the above attributes, will be handled by Turbo by default.

.changePage() changes page, but reloads previous page

I am developing phonegap application using jQuery Mobile. Below the code I have used to changes page when click on Button
$(document).on('click', '#btn_new_register', function (e) {
$.mobile.changePage($("#newuserregister"), { transition: "slide"} );
});
My problem is when I click button it load registration page but within a second it load previous page (Login Page).
I have use single page structure using jQuery Mobile.
Please help me on this.
I have seen questions asked on the stack overflow but didn't find solution.

Use jquery in juqeryUI tabs

I am loading a file in JQueryUI tabs, when I include the jquery file in the called file i am getting errors while switching tabs, I thought its due to conflict of the jquery as it is included in both calling and called files, the problem was solved when I removed the link from the called file. Now the file is loaded in tab, well I have something like few jquery operations to be done in that tab, as the jquery is not included I am unable to perform any stuff in that tab, what is the solution, how did they design those tabs so that a user cant include the main jquery file in all the ajax called files. Is there a solution or this is a bug or shall i give up using jqueryUI tabs?
Thanks
The content of the tab is part of the main page, which has jQuery in it. So you can select elements from the tab and call jQuery methods on them as if they were part of the main page. In fact, by the time you are able to call jQuery methods on anything on the page, i.e. after document.ready, it is part of the main page.
If you couldn't use jQuery with jQuery UI, you wouldn't be able to use jQuery UI, because that itself uses jQuery...

jquery mobile pagecreate event for dialogs

Hi jQueryMobile has an event for on pagecreate but it doesn't work with the dialogs (dialog page embeded in the same page with data-role="page")
$(document).delegate("pagecreate", "#foo-dialog", function() {
console.log("dialog-opened");
});
I have working code where pagecreate/pageshow is being called when showing a dialog, maybe you have your JS in the wrong spot? If you AJAX transitioned to this page any JS in your head tags isn't pulled in.

How do I create a confirmation dialog in jQuery Mobile?

I want to have a confirmation dialog (not plain javascript) show when the user clicks a button, but I'd rather have it embeded instead of referencing another page.
How do I embed a dialog for use on a jQuery Mobile page?
You have 2 options really - if you want it to popup and fill the page, you can create a JQM dialog page (even dynamicaly), and switch to it. JQM dialogs are explained more in detail here:
http://jquerymobile.com/demos/1.0b1/docs/pages/docs-dialogs.html
It is quite possible to append a new dialog to the same page (simple append it to the container above the one with data-role="page") and switch to it with $.changePage(...)
Another option, if you want it to popup "over" the existing content (modal mode from UI dialog), this plugin will do that:
http://dev.jtsage.com/jQM-SimpleDialog/
Full disclosure: I wrote the second one, so I am biased. However, it does employ a bit of option 1 above, and you are of course welcome to rip the code apart to see how it works if you'd rather roll your own.
Edit:
Another option is to use the builtin popup interface, added in the last major version (1.2.0 I think). It can be found here, and is included in the default:
http://jquerymobile.com/demos/1.2.0/docs/pages/popup/index.html

Resources