Results 1 to 12 of 12

Thread: [RESOLVED] How to keep form submittal from navigating away from page

  1. #1

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Resolved [RESOLVED] How to keep form submittal from navigating away from page

    Noob alert!

    I have a dojo dialog box that has a form on it. When I submit the values on the form to the server, the dialog dismisses like I want it to, but the whole page navigates away from where it is. I want to have the form on the dialog submit the info and dismiss, but leave the original page where it is.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: How to keep form submittal from navigating away from page

    What code are you using at the moment?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: How to keep form submittal from navigating away from page

    Right now I'm not using any code to post to the server - it's just a standard html form:
    HTML Code:
    <form action="~/FeatureDetails/EditFeature?MapFeatureID=@Model.TheFeature.Id&MapLayerId=@Model.TheLayer.LayerId" method="post" >
    
        <!-- form elements -->
    
        <p><input type="submit" value="OK" /></p>
    
    </form>
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  4. #4

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: How to keep form submittal from navigating away from page

    My apologies - I failed to indicate in the first post that this is an mvc app. Maybe that will help clear things up?
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  5. #5
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: How to keep form submittal from navigating away from page

    Having a "submit" button on your form will cause the form to post it's contents to the "action" url when the submit button is clicked. Sounds like you would want to change it to a regular button, either <input type="button" /> or <button type="button"></button> and then do an ajax post to the form's action url.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  6. #6
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,900

    Re: How to keep form submittal from navigating away from page

    I've moved the thread to the MVC section. You're likely to get better responses here.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: How to keep form submittal from navigating away from page

    As it's an MVC app, you should be using Ajax.BeginForm to create your form element. If you didn't want an asynchronous post then you should be using Html.BeginForm.

  8. #8

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: How to keep form submittal from navigating away from page

    I got snookered on Ajax.BeginForm since it's tied to the jQuery toolkit - I'm confined to using the dojo toolkit. I've found some example dojo code to perform the partial postback when the submit button is clicked, but it isn't working exactly right. Gonna have to do some more research.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: How to keep form submittal from navigating away from page

    Quote Originally Posted by dolot View Post
    I got snookered on Ajax.BeginForm since it's tied to the jQuery toolkit
    It's nothing to do with jQuery. It's part of the MVC Framework.

  10. #10

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: How to keep form submittal from navigating away from page

    My understanding is that jQuery's unobtrusive-ajax script has to be loaded into the page for the code that's generated by the Ajax.BeginForm function to operate. Am I wrong on that?
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: How to keep form submittal from navigating away from page

    Quote Originally Posted by dolot View Post
    My understanding is that jQuery's unobtrusive-ajax script has to be loaded into the page for the code that's generated by the Ajax.BeginForm function to operate. Am I wrong on that?
    Hmmm... I didn't think that that was the case but maybe I'm wrong.

  12. #12

    Thread Starter
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: How to keep form submittal from navigating away from page

    Here's what I finally came up with. Fairly simple, and it works.
    Code:
    function SubmitFeatureData() {
    
        require(["dojo/dom", "dojo/request", "dojo/dom-form"],
        function (dom, request, domForm) {
    
            var form = dom.byId('FeatureDetails');
    
                // Post the data to the server
                request.post("/FeatureDetails/EditFeature", {
                    // Send the username and password
                    data: domForm.toObject("FeatureDetails"),
                    // Wait 2 seconds for a response
                    timeout: 2000
    
                }).then(function (response) {
                   // dom.byId('svrMessage').innerHTML = response;
                });
           
            }
        );
    
    }
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width