How to cancel super call of a button click event through extension in Dynamics 365 FO? - x++

I want to add a check to the click event of a button, when check failed, I want to cancel the super call, how to do it?
I have tried to use FormControlCancelableSuperEventArgs and FormControlCancelEventArgs in event handler of clicking event, but both of them return null.
Below is my test code.
[FormControlEventHandler(formControlStr(LedgerJournalTable, Approve), FormControlEventType::Clicking)]
public static void Approve_OnClicking(FormControl sender, FormControlEventArgs e)
{
FormControlCancelEventArgs ce1 = e as FormControlCancelEventArgs; // ce1 returns null
FormControlCancelableSuperEventArgs ce2 = e as FormControlCancelableSuperEventArgs; // ce2 returns null too
}
I know I can complete it by throw exception, but I think it is not a official way.
So how can I cancel the super call by a official way?

I don't think it's possible to achieve what you want to. The super() call in the Approve button on the LedgerJournalTable form is doing nothing outside of the frameworks form management such as screen refresh and other tasks that won't affect the logic (because it is a regular button and NOT a menu item button). The button is creating a new menu function in code and calling it explicitly, but is not actually calling the menu item in the super() call.
I would create another approve button in an extension, hide the out-of-the-box button, and in your extension button's OnClicked event copy the logic from the original button, and then modify it in any way that you need, such as skipping the menu function call based on certain logic/conditions that your requirements dictate.

Related

setTerminal removes content instead of layout

Hi i have a zf2 application.
In my module i attach a listener to the MvcEvent::EVENT_DISPATCH event.
In this listener i check if the user is authenticated etc.
If the user is authenticated i change the layout.
Now if i call $viewModel->setTerminal(true) in my action no content is shown, just the layout but i need it the other way around.
https://stackoverflow.com/a/21441607/1594076
This answer somewhat explains what wrong i think but it's not real clear to me.
Also the solution provided is not working in my situation as i would have to add the 2 methods to all my controllers.
Anybody that has a solution?
Thanks
In your layout listener you'll need to apply some conditional logic to determine if the view model your controller returned is terminal before setting a layout.
This can be done by getting the result from the MvcEvent in your listener and checking it's a ViewModel instance that doesn't terminate()
public function yourLayoutListenerCallback(MvcEvent $e)
{
// get the dispatched result from the event
$result = $e->getResult();
// check it's a view model that doesn't terminate
if (!$result instanceof \Zend\View\Model\ViewModel || $result->terminate()) {
// do nothing
return;
}
// your existing layout logic ....
}
Note: you'll need to make sure your layout listener has a low enough priority (>= -10 seems to be enough) such that your controller action has actually returned the view model before testing the condition.

Custom ToggleButton in Xamarin.Android

I am working on a MvvmCross based android app. The app contains (among other things) a large number of ToggleButton(s). The buttons are added in .axml files. Their Checked property and Click event are bound to view-model properties. Since the Checked property of the each ToggleButton should reflect the state of some property on a application server, I don't want their checked state to be changed when the user clicks them, but only when the bound property on the view-model is changed. An example how this "special" toggle button should work: When the user clicks it, the "Checked" property of the button does not change only the ICommand to which the click event is bound to is invoked. The method invoked by the command in turn changes the value of the property on the view-model(if executed successfully). Extending a ToggleButton in WPF or Windows Forms to described functionality is easy but I don't know how to do that in android. Any ideas will appreciated.
Uroš
I found the solution to my problem. It seems it had to do something with the way I set up the bindings for my ToggleButton
MyToggleButton was implemented as:
public sealed class MyToggleButton : ToggleButton, View.IOnClickListener
{
public MyToggleButton(Context context, IAttributeSet attrs)
: base(context, attrs)
{
SetOnClickListener(this);
}
public void OnClick(View v)
{
Checked = !Checked;
}
}
As you can see I just set the Checked property back to previous value when ever the user clicks the button. In the asmx I use the following block to add the button.
<controls.MyToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
local:MvxBind="Checked Value;Click ClickCommand" />
As it turns out the problem with described solution is that the OnClick(View v) method is not executed when the user clicks the button as long as the .axms file contains binding to Click event. I have no idea why that is so I would love any explanation. The workaround I used is to define custom event in the derived class, raise the custom event in the OnClick event handler and than bind to that event.
Uros

MVC3 - How handling exception without redirect to another page and show errors in jQueryUI Dialog?

my actual example scenario is:
I have a Controller with a Action named Create(TClass obj).
When an error occurs, I wish fire an specialized exception (MyException), but I don't wanna to redirect to another page (General Page Error Handler, or others). I want to stay in the same page and show the message error in a jQueryUI Dialog popup.
I've tried these options:
Override the method OnException (in Controller)
Tested PostSharp (specializing OnExceptAspect)
Tested the solution in this link and others like.
Have you any idea?
Thanks.
Throughout your application in all your controller methods, call:
catch(Exception e)
{
errorModel errorModelInstance = new errorModel();
errorModel.message = e.Message;
errorModel.stack = e.StackTrace; //You get the idea...
return PartialView("someErrorView", errorModelinstance);
}
Then, have a someErrorView.cshtml file which contains the script reference for jQueryUI for the modal popup (unless your master layout already references it throughout the application), and have initializers for the modal popup in that partial view. (Let me know if you want the front-end code for initializing the popup).
This partial view will return the model "errorModel". You will have to define a class under your models folder to declare the string properties of the errorModel.

Pass a parameter from searchfield in blackberry

I'm new to Blackberry Development and i have to implement a search functionality. It is supposed to be like when i input something in the search field and press the search button it should pass that string to a url as a parameter. Can anyone put me in right direction so as i can understand how to implement it.
If you want the searching to be done on a remote server, and just want the user to be able to enter a search term, then you'll first want a manger with two fields, such as a BasicEditField and a ButtonField. Then you'll want to hook up the button field to submit a request when it is clicked (I assume from your description that is http, but it could be anything). If your button field is stored in a buttonField variable, and your edit field is stored in your editField variable, and you have a method named sendRequest that takes a parameter and sends a request to the url, then you might have:
buttonField.setChangeListener(new FieldChangeListener() {
public void fieldChanged (Field field, int context) {
(new Thread() {
public void run() {
sendRequest(editField.getText());
}
}).start();
}
});
This might look a little complicated, but it breaks down pretty easily:
By calling setChangeListener, we ensure that the fieldChanged method will be called whenever the button is pressed
When fieldChanged is called, we will be in the UI thread. We don't want to lock the UI while we make the request, so you should send the request in a new thread.
getText gets the current text that the user has entered, and passes it to your sendRequest method
The sendRequest method should send the request to the url you mentioned. This will differ depending on how old devices you need to support - BlackBerry introduced a new networking API in 5.0 and expanded on it in 6.0, that simplifies network communications significantly.
I'm assuming you'll be parsing some sort of response that holds the search results. In this case, you'll also want a manager (such as a VerticalFieldManager) to store those results. Then you would add a field for every result that you wanted to show. You'll need to be careful to be holding the UI event lock when doing this, however, since it will probably be executing in a background thread. For example, you might have:
public void addResult(String result) {
synchronized(Application.getEventLock()) {
searchResults.add(new LabelField(result));
}
}
This would just show results in a label field, but you could obviously have more complex fields if you wanted more complicated behavior or more complicated UI.

Rails - Access AJAX Triggering Element in Callback

I have a view, say show.js.erb. And I have a link in another view such that
link_to "MyLink", my_object_path, :remote => true
successfully returns the show.js.erb view. My question is, from within that view, is there any way to access the element that triggered the AJAX call without having to resort to generating an id specific to individual elements a la ...
I want to be able to use this view callback to open a small dialog next to whatever element was clicked on, but I can't seem to find a way to access the triggering element.
I tried using $(this) but that doesn't work.
I'd like to do something along the lines of
$(this).after("some new html here");
My solution was to bind a pre-submit class to the element, in my case a popup modal window. It's a similar solution to the post linked to above in that it uses the pre-submit bindings, but tailored to use classes instead.
In public/javascripts/application.rb:
jQuery(function($) {
$(".poppable").bind("ajax:loading", function() { $(this).addClass("popped"); });
});
Then in my view for the popup content (e.g. app/views/mymodel/popup.js.erb):
var p = $(".poppable.popped");
p.removeClass("popped");
/* Do what I need to with p ... */
If this doesn't look kosher, I'm all ears but it works for now.

Resources