Refreshing caller listpage form - axapta

I need to call parent form but my parent form is a listpage form.
As I know I can't add new methods to list page forms i need to add this method to the interaction class of related list page form. But I do not have an idea how to do it.
Would you have any suggestion for me?

You have two options:
Set the AutoRefreshData on the menu item on the list page. This will refresh the list page, I am not sure when (maybe it works best on action menu items).
Call element.args().record().datasource().research(true); from the child form.

You can refresh a datasource of a calling record.
You need to cast element.args().record().datasource() to FormDatasource so you can call research() or executeQuery() depending of you needs.
Also you can/must check if record is from a form by using method on common isFormDatasource(). If this is true than this record is from form.
If you need to refresh parent from another form you should do it in closeOk() method of this form or at the end of you logic in a class.

Related

Many forms for editing entity on one page

I have a list of objects on my page. I need to edit an object in a popup.
There are many objects, and generating many forms for each object is not correct.
What can I do, can an iframe do in a popup?
You don't need to use iframe.
Build your form in your controller and render it in the html. The fact that it's in popup doesn't change anything. It doesn't matter if it's in popup or not, the final result will be POST call to your action.
You should have an action that renders a form, callable from an ajax in the view where you have all those entities.
Just change the entity id that will be received in the action as argument by changing the ajax url using js depending on the clicked entity you want to edit.
Then return with the ajax the form already rendered so with only one form you can edit as many entities (of the same class) as you want, without even need to render one form before they click which one they want to edit.

How to handle Ctrl+n on a list page form?

I am trying to handle "ctrl+n" (create new record) action on a list page. I would like to start an wizard after ctrl+n is started. On a normal form I can do it on datasource in create() method. Methods on datasources are disabled on the list page. I can not find a way how to do this. I know it is done somehow on a PurchTableListPage but I can not find how.
How this action can be handled on form with listpage template?
It is on design "newRecordAction" property.

Refresh entire form in AX 2012?

I'm currently working with a form that has a grid at the bottom. Whenever I hit f5, the grid refreshes, but the rest of the form does not. What can I do to make the entire form refresh it's data?
Thanks.
You may override the research method on a datasource:
public void research(boolean _retainPosition = false)
{
super(_retainPosition);
other_ds.research(_retainPosition);
}
The other_ds is a datasource not joined by the current datasource.
It depends on the form you are working with. When you hit F5 on a record, it runs the research method on the datasource the record belongs to or its parent datasource (depends on the form's query, e.g. if you hit F5 on SalesLine in the SalesTable form, SalesTable_ds.research(true) will be run). As I see it, if the rest of your form displays fields that belong to these datasources then these fields will be updated. If the fields do not belong to these datasource the rest of your form will not be updated (unless e.g. the active method has been overridden to refresh the rest of the form from the code.
What you can do to make the entire form refresh its data when F5 is hit: again, it depends on the form, so not knowing all the details it is difficult to advise something, but one of the things you can do is override the research method on your datasource and refresh the rest of the form programatically from there. It is more common to override the active method, you should normally go for it.

how to use one field value in multiple forms

It is possible to have 2 separate forms on 1 asp mvc webpage, that using value of one (listbox) control ?
e.g.
using(beginForm) {
//form 1
ListBox("name")
//submit etc.
}
using(beginForm) {
//form 2
//submit2 etc.
}
that form 2 knows value of ListBox named "name" placed in first form ?
Nope - you can only send over what is inside that form without some trickery. You could use jQuery to hook into the form post and set the value dynamically based on what is in the other form.
This link describes how to hook the jQuery submit.
http://hasin.wordpress.com/2009/10/01/jqueryhooking-form-submit-and-making-it-an-ajax-request/
In your function you can then synchronize the values - the easiest way is to probably keep this field OUTSIDE of either form, and include one inside of each form. You only change the one outside of the form, and then on submit you would set each form field as such:
$('#txtForm1Field').val($('#txtPlaceHolder').val())
$('#txtForm2Field').val($('#txtPlaceHolder').val())
if you want them named the same thing you will need to select based on a form id first
Also remember you cannot embed forms within each other either.
There are other ways with jQuery (such as via ajax request just insert the value in the form data being posted) but you don't have anything 'by default' with html that would allow this because of the scope of each form.
If you can call the same view (also pass the model) from the post function of the first form then you'll get the data from from the list in the model. A better option would be to create a partial view.
As far as I feel if you pass the model while returning to the view then you'll get the data you require.

MVC2 - How put common LOGIC control (Like Search/Find) on each page?

I'm having trouble figuring out how to do the following:
On every page (or every page I so desire), I'd like to put a common control widget (e.g. think - Search functionality that contains a textbox+button). What's the best way to do this, and who handles the submit button (assuming it is a submit button)?
i.e. what does my ViewUserControl look like? Does it have a form? does it use jQuery onclick""? Does it post to the main View's action method, or can I redirect it to another Controller/Action?
I have tried using RenderAction of a "Search.ascx" which contains a Form, and is handled by my SearchController... but in the SearchController, it then tries to call RedirectToAction... and I get a complaint about RedirectActions not allowed on Child Actions.
I'm a bit lost on what to do next, so suggestions greatly welcome!
Ray
You seem to be on the right track (using ViewUserControl and RenderPartial). But with the information you have provided, it is not easy to see what you other problems are (RenderAction , ...)
It is easy:
Create a UserControl (.ascx) and get a form in there with URL being /search/..., something that you can get back.
In your views, call RenderPartial and provided the view name
Create your controller to receive the post from your search. This is not the same controller as your parent view controller.
The best way to have the HTML elements show up is to put them in a master page, or in a partial that is referenced by your master page. I would have it be it's own form and submit to your SearchController.
Let me know if you want more particulars.
RenderPartial is the way to go here. Your control.ascx will consist of it's form and submit button.
What's the best way to do this
Probably a partial view. An .ascx file.
and who handles the submit button
(assuming it is a submit button)?
The partial view
what does my ViewUserControl look
like? Does it have a form?
Yes, it has a form. It should be as self contained as possible.
does it use jQuery onclick""? Does it
post to the main View's action method,
or can I redirect it to another
Controller/Action?
Well, whatever fits your exact scenario best. It should probably post to whichever action is most appropriate. That is not likely to be the main view's action, since the partial is reused in different parent views.
I have tried using RenderAction of a
"Search.ascx" which contains a Form,
and is handled by my
SearchController... but in the
SearchController, it then tries to
call RedirectToAction... and I get a
complaint about RedirectActions not
allowed on Child Actions.
You'll probably want to render it using RenderPartial in the parent view:
<%: Html.RenderPartial("MyPartialView.ascx") %>
Ok, I figured out what my problem was. The replies above are correct. I have my own Search.ascx user control and SearchController, I also used RenderPartial, but what stumped me was that I forgot to explicitly specify the controller/action... so then I was fiddling around with onclick events and Url.Action on my button instead.
<% using (Html.BeginForm("MySearchAction", "MySearchController")) { %>
Thanks to all who replied.

Resources