Simrou icon indicating copy to clipboard operation
Simrou copied to clipboard

how to do a form post?

Open Devric opened this issue 11 years ago • 2 comments

i have setup these to listen for post

    route.addRoute('/search/:key') 
            .post(function(e, param){ console.log('things') })

    //   try these methods below in here

    route.start() 
  • i've tried to just use action="#/search/" method="post", it refresh the page
  • than i tried to use route.navigate / route.resolve ; aint working
  • than i've tried to form.on('submit', handler(e)) { e.preventDefault ); nothing happens
  • than i've tried use $.ajax(url : '#/search' + param, type: 'post'); still nothing happens

Just found the handleFormSubmit(e) method, so i put it into

var init = function(route){
     route.addRoute('/search/:key')
             .post(function(e, param){
                    console.log(param.key)
             });

     $('form').on('submit', route.handleFormSubmit );
}

this opens up 2 more new issues,

1- how to parse in the input field data 2- it triggered the function twice, i noticed it calls the _bind method in the stack, which than triggers my init() again


seems like the form post to it without jquery.listener,

which comes down to how to get the data from the field?


i finally got the data pass through using $('form').serialize(), have to use jquery.submit method and return false to do a double trigger and capture the var data before route.post(funciton(){ console.log(data) }) to use.

Doens't seems convenient, hope this will be solved with the other ticket passing data{}, as 2nd param to resolve/navigate/formhandler.

Devric avatar Mar 04 '13 09:03 Devric

The form handler is supposed to be register by default (unless you tell start() not to do so) - if this is not the case, could you please run the tests (by opening tests.html in your browser) and check that all tests pass?

nlessmann avatar Mar 07 '13 16:03 nlessmann

I will look into automatically passing the form values to the handler.

nlessmann avatar Mar 07 '13 16:03 nlessmann