I used a plain html button tag in my Visualforce page to call my javascript remote action. The html code looks like this:
<div class="button-group">
<button class="primary" type="button" ng-click="assignToFirm();">Assign Jobs</button>
<button class="secondary" type="button"><a href="/{!order.Id}">Cancel</a></button>
</div>
The issue on chrome is, the browser doesn't wait for javascript remote event to come back. It refreshes the page (partially) straight away after making the ajax call.
Then I learnt that <button>
tag in different browsers have different default types. So the fix to the above issue is simple. I just need to specify the button type. As in this code:
<button type="button">Assign Jobs</button>
However, this makes me curious about how Visualforce page respond to form post event. Let's suppose we do have a <button type="submit">
on the page. If I click that button, how would Visualforce page respond to it?
It seems to me that Visualforce page is submitting the <apex:form>
content back to the server, but not the whole ViewState. Since the resulting page doesn't seem to have the state of the controller, nor does the constructor of the controller seem to be called. Is there a way in the controller we can define how we respond to these post events?