Submit a form in a jQuery Dialog box and close upon successful POST to MVC Action - asp.net-mvc

I am using the method from this question to create a pop-up to show a form where the user must "sign" it and then click submit. I have the pop-up working and displaying data. Now I want to submit the form to a POST action and close the pop-up if the POST was successful.
I have been scouring the internet looking for something close to what I think I am looking for, but seeing anything. Can someone offer me some direction?

You can either do it manually via http://api.jquery.com/jQuery.post/ (it has on success callback) or use jQuery ajax form plugin http://jquery.malsup.com/form

Related

Modal creating a log without changing the page

My page display a list of question. Near each question, a button switch a hidden statement to display a model over the page asking for some information. The goal would be, after the user complete the information and click submit, to access the backend and send the information to the database WITHOUT loading another page. I would like this popup to close and the user to resume what he was doing as if he did not do anything.
How would I go about doing something like this ?
You can use ajax and send a Post HttpRequest to an action which would then be tasked to save those information.
Please refer to this thread and this for more info.
Hope this helps you.

Open new window from GSP and forward to external URL

I need some help. I am converting a Struts application to Grails.
There is a particular action I am trying to convert.
There is a form in a jsp that asks a user to select a customer from a dropdown list and the user clicks one of two buttons.
When the user clicks on the "View Reports" button, an onclick event calls a javascript function that issues window.open on a STRUTS action class, passing the selected customer and selected action.
In the action class the http request has some attributes set (request.setAttribute (..)) and a forward is performed to an external application. The attributes that where set are used by the application for sign on. This is done as a POST.
My problem is I am not quite sure how to wire this flow using the Grails framework. I was able to get as far as the user selecting a customer, clicking an actionSubmit button, reading the selected customer from params, adding my attributes to 'request' and then..I am stuck.
How to open a new window? (Tried javascript way as was done with Struts).
Also I am able to issue a redirect to the external site in the controller, however a redirect is done as a GET and not a POST, as well as the redirect is done in the same window. Any help in laying this out would be awesome. Thanks
You can't redirect a user from server using POST.
I can see some possible solutions:
1 . If you don't need to pass through your server to validate or request some data, you can use this:
<form action="http://someotherserver.com" method="post">
2 . Create a controller that redirect to a page in your own site and in this page make a treatment that receives the paramters and then redirect the user to another domain using ajax.
In Grails, I've used createLink, with the 'base' attribute to do this.
<g:createLink base="${params.dynamicURL}">Link</g:createLink>
I think something like this would work, but you can research it here: http://grails.org/doc/latest/ref/Tags/createLink.html

How to build Preview functionality before form submit in Rails ?

I have a simple scaffold and I want the user to see (preview) the form data before he submits it. It looks to be fairly straight forward problem but surprisingly I am not able to figure out how to do it. I found this but it looks to be somewhat dated (2010 question)
Is there any gem or jquery plugin which can simplify this preview functionality ? any suggestions on how to do it in rails 3.2.x ?
Thanks
It really depends on what kind of "preview" you want to include - either "preview page" or "rendered fragment":
Preview page is what some services are showing: summary of all inputs shown in form of separate page with button "confirm". It doesn't require javascript or anything fancy - just click "next" on form page, see data typed just a second ago and click "confirm" or "back to edit". If this is what you require then you can do it simply by creating new controller action(preview?) which would initialize model with passed parameters(just like "create" action would, but without saving) and generate template with "preview" shown and hidden form that will be passed to "create" action after clicking "confirm". Alternatively you can simply modify "new" form so it would hide form depending on called action and show preview instead.
Second option is "render fragment" - it will live-update part of your current page via javascript. Depending on how complicated this view will be and what kind of operations you will need to do before showing template it might be good to use some javascript plugin or send request to server and obtain rendered partial. In former case you can select from very easy implementations(like this) up to complete solutions dedicated to it. On the other hand if you choose to render it on server then simple ajax request with all params of form should be enough to provide you with HTML output that can be put directly into DOM element.
I don't know about any gem which can do that.
I think showing a modal with jquery and getting data from data-elements is a simple way to go.

jquery mobile - MVC: How to save input from popup dialogs

Newbie here, scratching my head on this one.
How do you normally save information specified in a popup dialog for use by other forms on your page?
Scenaro:
Click an options button, which pops up a dialog.
Set some checkboxes, radio buttons, etc...
Submit form (dialog seems to need it's own form)
Do you usually just save the inputs in a session, cookie, or do you have another way access your dialog controls from the main form?
Seems like I'm missing something basic, as it should be easy to set some options and use them on the rest of the page.
All advice appreciated!
If you are trying to pass data from one page/dialog to another see Passing parameters between pages

Ajax login dynamic popup dialog

I thought this should be pretty well documented, because it seems like a pretty common scenario. Unfortunately, I find a lot of conflicting information out there and no real consensus on the correct way to go about this in an MVC 3 compatible, unobtrusive Ajax sort of way. I can certainly hack together something that "works", but i'd rather do it the way it's supposed to be done via the framework.
Here's what I need. I have Login link in the upper right corner of the site. The site allows both authenticated and unauthenticated users. So, I want to have a dynamic ajax popup when the user clicks the Login link.
This should go out to the controller, and pull back the HTML for the login dialog. It should then be displayed in a jquery ui popup dialog, and when the users enters their information it should redirect them to the "Dashboard" page (regardless of what page they are currently on). If they enter the wrong credentials, it should stay on the current page with the popup dialog still open and display validation errors ("username or password incorrect").
In other words, it has to tie into mvc 3 unobtrusive validation and use unobtrusive ajax, and display things in a jquery ui dialog.
This seems to be less trivial than I thought it would be. Any pointers to an example that does this? Anyone have a sample they can share?
UPDATE:
The conventional wisdom is, if you need to redirect, don't make it Ajax. However, in this case Ajax is required because I need to validate the creditials and post validation errors without causing a page refresh, or a redirect to a different login page. I need for the authentication to go through and post the errors in the popup dialog.
Seems like what you are looking for: http://evolpin.wordpress.com/2011/04/26/asp-net-mvc-partial-view-and-ajax-real-world-example/
Take a look at the MVC 4 Developer Preview. They have implemented the logon and registration process as popup dialogs in the skeleton app that is generated when you create a new app. There are a lot of other cool features worth checking out in this preview. Here is what the popup looks like for logon. It uses JQuery UI.
The point about MVC 4 login preview is that it can be used in two modes. As a Ajax/jQuery popup or standard form.
It does have a bug. It doesn't handle cancelation properly.

Resources