How to change command of formcommandbuttonControl dynamically in d365? - axapta

I have a form with a formCommandButtonControl in d365. I want to change the command associated to the button dynamically according to the condition in the code. I can't find any base enum to choose the value.
switch (x)
{
case 1:
formButton.command(New);
break;
case 2:
formButton.command(DeleteRecord);
break;
}
This is the property in the form
How can I choose New and deleteRecord value in x++ code?

Unfortunately, the answer to your question is do not do that and there is no enum.
When dynamically creating command buttons (FormBuildCommandButtonControl vs FormCommandButtonControl), the Microsoft convention has been to just use a constant (#define.New(260)) and reference that.
It is unheard of to dynamically change a command button's command and I don't believe it's done anywhere in the system.
The command button's text most likely won't update dynamically so you'll have change that too.
You should use a regular button for your purposes or create multiple command buttons and adjust their visibility as needed like the comments say.

The most obvious way is to provide two buttons only showing the relevant.
newButton.visible(x == 1);
deleteButton.visible(x == 2);
Mark the AutoDeclaration attribute of the control.
The code placed in init or active method where appropriate.

Related

VS windows forms

I was just wondering is there a less bloating and simpler way of clearing input elements say made up of text boxes, check boxes and combo boxes to a empty state, that being removing text from them etc. I have like maybe 50+ and was hoping of a tidier way of doing this.
Another scenario I have is a set of 18+ elements, each set having 2 text boxes and 2 check boxes, one being an 'enabled' check box that when selected will enable/disable its set. Would there be a way of creating a method to handle this and make the required changes rather than having to type out the same thing happening for each set?
if (cbEnhancedInputOptionEnabled1.Checked == true)
{
tbEnhancedInputOptionText1.Enabled = true;
tbEnhancedInputOptionInputID1.Enabled = true;
cbEnhancedInputOptionDefaultState1.Enabled = true;
}
else
{
tbEnhancedInputOptionText1.Enabled = false;
tbEnhancedInputOptionInputID1.Enabled = false;
cbEnhancedInputOptionDefaultState1.Enabled = false;
}
so I would have 18 of these just changing based on the number which correlates to the set. Each one being in their own cbEnhancedOptionEnabled_CheckedChanged event.
Is there a way of passing controls by reference to a method? that'll do the same as above but to the controls passed?
For the first scenario, you can create a method named, for example, ResetAllControls, where you can set the status of each control to its default state.
For the second scenario, you may implement CheckedChanged event for each checkbox to control what to be enabled/disabled.
Another option is to give prefixed name for each control in each set. For example, set1_txtBox, set2_ddl, etc. Then define a common method. The method should accept a parameter (based on the prefix or set order number) to decide which set that you want to enable/disable. In that method, you can loop through the list of controls of the Form and, based on the parameter, and enable/disable which controls that you wish. Finally, you can implement the CheckedChanged event for each checkbox that is responsible for enabling/disabling each set's status. In each CheckedChanged method, you call the common method and pass your parameter.
Let me know if these help you.

Update shiny input from java script

I've looked around and tried a few things but I can't seem to get it to work. I want to be able to update the value stored in input$someVar from a bit of js code. What I need to on a certain element click, I need to update the input$someVar value. I know there are functions like "updateSelectInput()" but those are called from the server.
I can physically change the value of the data in the HTML that is used int he data attribute and that is displayed, but the server doesnt see this as a change and the input$someVar stays the same.
I have tried
var selectBind = Shiny.inputBindings.bindings[5];
selectBind.binding.setValue('#loc', newValue);
within an event handler, where #loc is the id of the input element, in hope that I could do it that way but this gives me an error.
Is there a way to do the functionality of "updateSelectInput()" within java script in the ui?
Yes, there is a way. Use the JavaScript function Shiny.onInputChange.
// change the value of an input
document.getElementById("id").value = "value";
// report the change to shiny
Shiny.onInputChange("id", "value");

Visual Studio SDK - How to add a margin glyph on command invoked?

How can I modify this sample: https://msdn.microsoft.com/en-us/library/ee361745.aspx to have glyphs added to the margin when a button I added is clicked?
I have a button which creates a special kind of breakpoint. I would like this kind to be recognized by my own margin glyph. So I wrote the GetTags method in my Tagger class as follows:
IEnumerable<ITagSpan<MyBreakpointTag>> ITagger<MyBreakpointTag>.GetTags(NormalizedSnapshotSpanCollection spans)
{
if (BreakpointManager != null)
{
DTE2 ide = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;
Document document = ide.ActiveDocument;
foreach (SnapshotSpan span in spans)
{
ITextSnapshot textSnapshot = span.Snapshot;
foreach (ITextSnapshotLine textSnapshotLine in textSnapshot.Lines)
{
if (BreakpointManager.IsMyBreakpointAt(document.FullName, textSnapshotLine.LineNumber + 1))
{
yield return new TagSpan<MyBreakpointTag>(new SnapshotSpan(textSnapshotLine.Start, 1),
new MyBreakpointTag());
}
}
}
}
}
However, glyphs are added after moving the cursor to a different line of code or making changes to the code. What do I have to do to have glyphs added right after the button is clicked?
GetTags is called by the editor whenever a layout happens, but the editor won't call it for any random reason. (Think: how would it know when to call you?) You need to raise the TagsChanged event from your tagger to say the tags for a given span changed, and then it'll call GetTags again to refresh.
As an unrelated piece of advice: you shouldn't be using DTE.ActiveDocument in your GetTags for a few reasons:
GetTags should be as fast as possible...calling DTE methods are rarely fast.
Imagine you have two files open, and GetTags is called for the non-active file. That would have both files looking at the same filename which is probably bad. There's code here that shows how to fetch the file name from an ITextBuffer.
This is copied from my answer here. Basically, changing from using ITaggerProvider to IViewTaggerProvider allowed me to redraw the glyphs. I used the Implementing a Brace Matching Tagger Provider section in Walkthrough: Displaying Matching Braces example to make these changes.
Using the IViewTaggerProvider, you can then call
TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(
new SnapshotSpan(
SourceBuffer.CurrentSnapshot,
0,
SourceBuffer.CurrentSnapshot.Length)));
in your functions to explicitly call GetTags and go over the spans in the current snapshot.

objective-c if-else statement

I have both a UITextLabel and a UITextView occupying the same real estate, point-for-point in my view. I have an NSMutableArray allocated to populate the UITextLabel based on what the user taps in a table. I would also like to program the app to use the UITextView if and only if the user taps on one specific row. I think this can be accomplished with an if-else (if) statement, but I'm not sure. If that will work, I don't know what to put in the if part. So far, I have this:
if (qux == ??) {
fooTextView.text = textString;
} else {
fooTextLabel.text = textString;
}
I don't know what to set the if statement to. I tried to set it to
if (qux == the really long code containing the single array statement
I want displayed as a UITextView)
but that returned an error. Does anyone have a suggestion on how to get Xcode to recognize my single NSMutableArray table cell with the UITextView and not (also) with the UILabel? As of right now, the app builds but displays the text both in the UITextView, so it scrolls and does exactly what I want but also displays in the UILabel and is static and visible "underneath" the scrolling UITextView.
Also, I'm using an NSMutable Array with initWithObjectAndKeys. In this special case that is the only one of its kind in my UITableView, I use a special key that is only used by this particular part of the array. Is it possible to set it up so it's something regarding:
if (qux == *NSMutableArray with the special key*) {
fooTextView.text = textString;
} else {
fooTextLabel.text = textString;
}
And should I be using an if-else if statement or just an if-else statement?
Use the UITableView Delegate method didSelectRowAtIndexPath: you can get you row index from the NSIndexPath (indexPath.row). The you can use an if-then or a switch to determine which of your controls gets the data. Make sure you set your UITableView's delegate property to your file owner so the UITableView will call back to you controller.
HTH

Why can't I move a field into a fieldset in a Drupal form - fails to pick up current value

I have a node form in Drupal 7, in order to simplify it for the user I want to break it up into sections using the vertical tabs feature.
Using hook_form_FORMID_alter() I can move the fields without difficulty. When the node is saved, it writes the values correctly, and they appear in the node view.
But when I re-edit the node any value for a moved field is not set so I effectively lose the data. I've tried various options including changing the array_parents value in form_state['fields'][field][langcode].
(I wondered whether it would be better to move the fields during pre_render instead.)
Any ideas?
Field API fields by default are placed into a container field type. If you want to convert them to a fieldset in the vertical tabs, you can do the following:
$form['field_tags']['#type'] = 'fieldset';
$form['field_tags']['#title'] = 'Tags';
$form['field_tags']['#group'] = 'additional_settings';
A better solution would be to use the new Field Group module so you can make these modifications through the UI, rather than in code.
Sometimes it works better to move field items around in the #after_build step of the form creation process.
in hook_form_alter, you set your after build function like so:
function mymodule_form_alter(&$form, &$form_state, $form_id)
{
$form['#after_build'][] = 'mymodule_myform_after_build';
}
Then you define your after_build function like so:
function mymodule_myform_after_build($form)
{
//do stuff to the form array
return $form;
}
I think you can even define after_build on individual elements.
Anyway, it's a good way to alter the form after all the modules have done their thing.

Resources