Multiple forms on one page - django-forms

For example if i have 3 forms on one page, how can i check in my view function which form was posted?
form1 = FormClass1
form2 = FormClass2
form3 = FormClass3

All of them will be posted unless you put them in separate form tags with separate submit buttons.

Related

Form validation not working with tabs x in yii2

I am using kartik-v tabs x. My paage has 3 tabskartik v tabs x
In each tab there is a form and a grid.
The form validation works in the first tab but not working in the inside tabs. The form is rendered using renderAjax. Also none of jquery work in the inside tabs.
Can anyone help here?
I could solve the above problem.
When you use tabs and there are forms in it. Each form should have a separate id.
Then the default YII validation works for all tabs
You have to use pjax;
inside the rendered view you have to add this:
Pjax::begin();
$form = ActiveForm::begin(
ActiveForm::end();
Pjax::end();
So u can use pjax for the validation. Let me now if it works.
I have 3 tabs and two of them have both a form and grid and the third only has a grid. The validation and submission all will work if you use different ids for your forms and your js function names should be different.

How can show MDiChild form as Modal?

When I try show form take this error "MDI child forms cannot be show modally". Can Someone help me?
Ty
You can't show that form as a modal form - it just isn't allowed. However, as a work-around, you could put the GUI of the current form into a UserControl. You then put the UserControl in your MDI Child form, so that it resizes to fill the form. Likewise, you can create a different, non-MDI form to contain the UserControl when you want to show it as a dialogue.

Partial View Submit inside Parent View MVC 3 w/Razor

I have three partial views that I load into a div based on radio button selection using jquery. Everything works fine on the loading and on the forms, however each partial form has a submit button(none on the parent form). I begin each partial form with:
<div id="newTicketPartial">
#using (Ajax.BeginForm("CreateNewTicket", "SubmitTicket", new AjaxOptions() { UpdateTargetId = "newTicketPartial", HttpMethod = "POST" }))
The issue is that within this form once I finish entering data and click the submit button it seems to skip this forms ajax post back header and instead uses the parent views #using Html.BeginForm
If I put an action and controller in the parent forms BeginForm field it will use that, otherwise there is an error. My problem is even if it does use the parent views POST path my controller only returns the partial view that I was editing, which updates the entire page. I need to be able to submit information from each partial view and have only that partial view be updated, not the entire page. I am open to suggestions of ways this can be done. If more code is desired I will post more.
Nested forms are the issue. You should not nest forms, or else any buttons further down the page (even those generated by partial views) will cause the parent form to POST.

How to get parent view from partial view

I have a partial view as part of the _Layout.cshtml, so that it gets rendered on multiple pages. Think of the partial view as a menu that gets displayed on every page on the website.
When one of these links in the menu of the partial view is clicked, I can only access/see in the Action Method that gets called the partial view, like it's name etc.
But what I really need to have is the View that the partial view was on when the item was clicked.
How can I get this?
You can use ParentActionContext
For example
var controller = ControllerContext.ParentActionViewContext.RouteData.Values["Controller"] as string;
var action = ControllerContext.ParentActionViewContext.RouteData.Values["Action"] as string;
Update
From the view this call should do what you need
#HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString()
#HttpContext.Current.Request.RequestContext.RouteData.Values["action"].ToString()

MVC3 Restricting validation to the submitted form only

I have a view with two forms on it. Each form is marked like this:
Html.BeginForm("Details", "Forum", new { page = Model.PagedList.CurrentPage }, FormMethod.Post)
And each form has its own input button (type="button").
My problem is, when I click the button for one of the forms, the validation errors for the other form are added to the ModelState, so ModelState.IsValid == false.
How can I limit the scope of the validation to just the form I am clicking a button on?
Use Shared View instead to control your validations on different form.

Resources