Anchor as a Submit button - asp.net-mvc

I have an MVC 2 application that has the following on it;
<% using( Html.BeginForm("Results","Quote", FormMethod.Post, new { name="Results" })){ %>
<% Html.RenderPartial("Needs", Model.needs); %>
<div class="But green" style="">
Go
</div>
<input type="submit" />
<%} %>
Pressing the Submit button or the anchor both post back to the right ActionResult.
However, when in the controller I return View(stuff..) only the Submit button will come back to the page.
When the call finishes from pressing the anchor, I go to an error page informing me that the resource cannot be found.
I suspect it has something to do with href="." but am unsure what to set it to.

You could try and just use a # in the href - empty in-page link I guess you could call it.
<div class="But green" style="">
Go
</div>
That way it should work on any page without worrying about specifically setting the href to the view you're trying to return.

I have it.
<div class="But green" style="">
Go
</div>
href needs to be set to the view i'm trying to return.

Related

Grails formRemote updating wrong div

Having a comment within a comment but I'm having trouble in updating via form remote in correct place
I have this code
<div id="comment">
<g:render template="comment" var="comment" collection="${review.comment}" />
</div>
<g:formRemote class="ui comment form" name="commentForm"
url="[controller: 'game', action: 'addComment']" update="comment">
The problem is it's updating correctly in the database. but In the view it is only updating in the top most parent comment and not the correct comment
Sample pictures:
After clicking Add comment button :
After refreshing the page:
Don't mind the miss arrangement on the last picture I have a little sorting problem which I'm gonna fix later, the problem is the formremote updating the wrong one. The last picture is just to show that the update in the database is correct
edit:
Here is the action and template
def addComment(){
gameService.addComment(params.comment, params.gameId, params.userId, params.reviewId)
def comment = gameService.listComment(params.gameId,params.reviewId)
render(template: 'comment', collection: comment, var: 'comment')
}
template:
<div class="comment">
<a class="avatar"> <img
src="${createLink(controller:'user', action:'avatar_image', id:"${comment.user.id}" )}" />
</a>
<div class="content">
<g:link class="author" controller="user" action="userProfile"
params="${[userId:"${comment.user.id}"]}">
${comment.user.name }
</g:link>
<div class="metadata">
<span class="date"> ${comment.date }
</span>
</div>
<div class="text">
${comment.comment }
</div>
</div>
Looks to me like your first piece of code already is used multiple times, resulting in more than one div with the id "comment" (I guess that because you have multiple textareas and thus multiple forms in your screenshots, and this would totally explain your problem).
So, if you have multiple div-tags with the same id, the formRemote places the returned html inside the first one.
Edit: damn, just noticed that this question is quite old :-/

Uncaught Error: Nothing handled the action 'edit' - Correct controller name to put the action

First of all,I am new to ember.I have a "show" handlebar inside "templates/orders/show.hbs" . The form submit action in this handlebar always returning "Uncaught Error: Nothing handled the action 'edit'. If you did handle the action, this error can be caused by returning true from an action handler in a controller, causing the action to bubble." . I have the edit action defined in controllers/orders.js. Am i placing the edit action in wrong file. If so, what would be the correct place to have the "edit" action.
Handlebar(show.hbs):
<form class="form-horizontal" {{action "edit" this on="submit"}}>
<div class="control-group">
<div class="control-label">
<label>Name</label>
</div>
<div class="controls">
{{input value=name type="text"}}
</div>
</div>
<div class="control-group">
<div class="control-label">
<label>Age</label>
</div>
<div class="controls">
{{input value=fury type="text"}}
</div>
</div>
<button type="submit" class="btn">submit</button>
</form>
controller file (orders.js):
export default Ember.ObjectController.extend({
actions: {
edit: function(){
console.log('EDIT - Entered');
}
}
});
Thanks!
As it was pointed out, your question is a bit vague as to how you're rendering your template.
First, make sure you have the Ember inspector installed. There are versions for Chrome and Firefox, and likely other browsers. This will make debugging your Ember application a lot simpler. With the Inspector installed and open, navigate to the "View Tree" and you should be able to figure out which controller is the active controller for your template.
With the syntax:
{{action "myAction"}}
The action will bubble to the controller that is currently responsible for the template. Additionally, if your template is rendered within a view and you want the view to handle the action and not the controller, you can specify:
{{action "myAction" target="view"}}

Successive form submission without losing data in Rails?

I am confused between the controller and views interaction. I have this initial form which validates the csv file uploaded. (POST form).
After this form is validated successfully, I give the user the option to confirm the details which, and this confirm button acts as another form.
The thing is I want to keep the details from the previous form values saved in the params hash. So basically I want to perform a merge with the second form.
Is this possible? If so, can you help me with the code for the second form cause currently it overrides the previous form. Both forms point to the same function in the controller.
<% unless #contents.blank? || #errors.present? %>
<form name="confirm_bulk_order" method="post" enctype="multipart/form-data" class="search line" action="/orders/create_bulk_order" id="confirm_bulk_order">
<div class="search-btn-align" id="confirmButton">
<input type="submit" name="confirm_bulk_order" value="Confirm Order" class="lmargin10 uiButton">
</div>
</form>
<% else %>
<form name="upload_bulk_order_csv" method="post" enctype="multipart/form-data" class="search line" action="/orders/create_bulk_order" id="upload_bulk_order_csv">
<div class="fileformField">
<span class="formlabel"> Upload CSV File: </span>
<input class="required" required="true" type="file" name="datafile"/>
</div>
<div class="search-btn-align" id="uploadButton">
<%= submit_tag 'Validate Bulk Order', :class => 'lmargin10 uiButton' %>
</div>
</form>
<% end %>
In controller orders
def create_bulk_corder
if #errors.blank? and params[:confirm_bulk_order]=="Confirm Order"
#Send the final REST order call
else
#contents = read_csv_file(params[:datafile]) if params[:datafile].present?
validate_order(#contents)
#Populate #errors etc, etc
....
....
end
render
end
What all changes must I make for this to be possible?
You're losing your params when the confirm button is pressed because they're not part of the confirm form. You could avoid this by adding a hidden field:
<form name="confirm_bulk_order" method="post" enctype="multipart/form-data" class="search line" action="/orders/create_bulk_order" id="confirm_bulk_order">
<!-- This assumes that #contents is a simple value... it's probably not, so you might need several hidden_field_tags here, one for each part of #contents that you want in your params -->
<%= hidden_field_tag "contents", #contents %>
<!-- You probably also want to show the user some info about their submission here -->
<div class="search-btn-align" id="confirmButton">
<input type="submit" name="confirm_bulk_order" value="Confirm Order" class="lmargin10 uiButton">
</div>
</form>
If you go with this approach, be sure to re-validate params[:datafile] after submission, since a malicious user could change this param value to get around your validation logic.
Also, I suggest factoring your action into two separate actions, and likewise for the views. You've got if-else blocks where you really ought to have separate files.
I suggest maybe using a gem that deals with multi paged forms or wizards: https://www.ruby-toolbox.com/categories/rails_wizards

Display submit button in header

I'm currently porting a jQTouch web project to jQuery Mobile and have run into the following issue: I need to display a form submit button in the page header, but unless I make the submit button an action in the header (instead of an input of type submit in the content) jQuery Mobile will always render that button as part of the form.
This will work (button will show on the right side of the page header):
<div data-role="header" data-theme="b">
<%: Resources.View.Account.Labels.DoLogOn %>
</div>
Thing is, I'd have to write custom javascript to trigger the submit, which obviously I'd rather not. If, on the other hand I handle this inside the form, i.e.
<% using (Html.BeginForm("LogOn", "Account",
new { returnUrl = Request.QueryString["ReturnUrl"] }, FormMethod.Post,
new { #class = "ui-body ui-body-c" }))
{%>
<fieldset class="ui-grid-a" data-theme="c">
<input data-icon="check"
class="ui-btn-right"
type="submit"
value="<%= Resources.View.Account.Labels.DoLogOn %>" />
</fieldset>
<% } %>
the button will be displayed inside the content.
Is there a way to make jQuery Mobile display the submit button in the header using the latter approach?
I know I'm a few months late, but I came across this post researching another problem. To submit a page from a button in the header you can use the following button markup:
<a href="#" onclick="$('form#Account').trigger('submit')" class = "ui-btn-right" data-role="button" >Logon</a>
I am not familiar with jQTouch, but how about something like the following?
The issue is probably around the css classes used and where you have used them.
<% using (Html.BeginForm("LogOn", "Account",
new { returnUrl = Request.QueryString["ReturnUrl"] }, FormMethod.Post))
{%>
<div data-role="header" data-theme="b">
<fieldset class="ui-grid-a" data-theme="c">
<input data-icon="check"
class="ui-btn-right"
type="submit"
value="<%= Resources.View.Account.Labels.DoLogOn %>" />
</fieldset>
</div>
<div id="Content" class="ui-body ui-body-c">
...content here
</div>
<% } %>

Html.BeginForm in partial for a different controller

I have the following code:
<% using (Html.BeginForm("AddComment", "Comments", FormMethod.Post)) { %>
<div id="New_Comment">
<textarea name="newComment" id="newComment">Add comments</textarea>
<input type="submit" value="Add" />
<div><span class="text_grey">Attach:</span>File Link</div>
</div>
<%} %>
This is in a partial rendered by the MyPage controller. For some reason the action on the form comes out blank, if I reference a method on the MyPage controller it works fine what I want to do is point to a different controller with my form.
To solve this issue I simple added in an area route value like so:
new { area = "" }
With the empty string directing the route to the default area.
1) Is your "Comments" action marked as being a POST action?
2) Also
Try just doing:
<% Html.BeginForm("AddComment", "Comments"); %>
// Html and script
<% Html.EndForm(); %>
I know that there shouldn't be difference between what you have and what I suggest, but it's worth a try.

Resources