How to hide a vanilla button according to form state - dynamics-crm

I am trying to hide my SAVE vanilla button according to form state. when the form state != create the vanilla button should not display. I tried different things but nothing works:
I create a function in js that returns true if form is create state
function isHideState(){
formstate = Xrm.Page.ui.getFormType();
if(formstate == formType.create){
return true;}
else{
return false;}
}
I added a disply rule and connected it to my command that relevant to the js function :
my rule is : FormStateRule and state: Create
I connected my command to my vanilla button and yet it display even if the form is'nt in create state.
Am I missing something? it's been hours.. guidance someone?
UPDATE: to be more specific - I need the button to be seen only on create mode.

We do not need to use JavaScript here, instead of Display rule, please use Enable/Disable rule and apply the FormState rule.
Please see below image

Note: Whenever you are customizing the vanilla button (OOB Save button in your case), Make sure to start by right click the button in Ribbon workbench & click customize button/command to “retain” the OOB behavior & add your customizations on top of it.
Change this line
if(formstate = formType.create){
into
if(formstate == formType.create){
Single = is for assignment; double = is for comparison.
Update:
RibbonDiffXml follows/expects this structure in command:
<CommandDefinition
Id="String">
<EnableRules />
<DisplayRules />
<Actions />
</CommandDefinition>
There’s no direct property for rules in Button; only command can be linked.
<Button Alt="String"
Command="String"
CommandType=["General" | "OptionSelection" | "IgnoredByMenu" ]
CommandValueId="String"
Description="String"
Id="String"
Image16by16="String"
Image16by16Class="String"
Image16by16Left="Non Positive Integer"
Image16by16Top="Non Positive Integer"
Image32by32="String"
Image32by32Class="String"
Image32by32Left="String"
Image32by32Top="String"
LabelCss="String"
LabelText="String"
MenuItemId="String"
ModernCommandType=[ "ControlCommand"| "System"]
ModernImage=”String”
Sequence="1"
TemplateAlias="String"
ToolTipDescription="String"
ToolTipHelpKeyWord="String"
ToolTipImage32by32="String"
ToolTipImage32by32Class="String"
ToolTipImage32by32Left="Non Positive Integer"
ToolTipImage32by32Top="Non Positive Integer"
ToolTipShortcutKey="String"
ToolTipTitle="String"
/>
After 2013, commandbar introduction changed the behavior of Enable rule similar to Display rule. Disabled buttons using Enable rule will hide the button to utilize the space for other buttons in command bar (as there are always limitation like 7 or 9 buttons in command bar unlike Ribbon).
Enabling buttons again will act like show/hide once switched (similar to Display rule). Probably you can follow this blogpost to achieve yours.
An important thing to remember is to add the enable rule(s) to the command. This is commonly missed, someone creates an enable rule but forgets to add it to the button command.
If you forget to add enable rules to the command then the button will show on all states/stages of the form. If you forget to add the command to the button, then the button will not show up on the form.

In the ribbon editor, you can add Display and Enable rules. You can check the form type with no code. Look at this video:
https://www.youtube.com/watch?v=xyLzEAW0CJs

Related

How to specify a particular order of buttons in a JavaFX 8 Alert

I need to ask the user to confirm doing an action. The set of buttons of the confirmation dialog are "Yes", "No" and "Cancel". My code is below:
private ButtonType askYesNoCancel(String question) {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setContentText(question);
alert.getButtonTypes().setAll(ButtonType.YES,
ButtonType.NO,
ButtonType.CANCEL);
return alert.showAndWait().get();
}
which gives me
The problem I am facing is that regardless in what order I specify the ButtonTypes for an Alert, I get the same button order (No - Cancel - Yes). I took a look at API documentation for Alert, Button and ButtonType, alas, not to find an answer.
What I try to accomplish, is the button order Yes - No - Cancel. Any advice?
Example if you really need to specify button order...
private static class FixedOrderButtonDialog extends DialogPane {
#Override
protected Node createButtonBar() {
ButtonBar node = (ButtonBar) super.createButtonBar();
node.setButtonOrder(ButtonBar.BUTTON_ORDER_NONE);
return node;
}
}
And then when you create your Alert.
alert.setDialogPane(new FixedOrderButtonDialog());
Check the answer to: Enter Key Event Is Not Working On Dialog In Javafx?, though I guess that answer more appropriately belongs with this question and perhaps doesn't fully explain what is going on. Also read the ButtonBar javadoc.
Basically, the button position is determined by a combination of the ButtonType of each button and the ButtonBar's buttonOrder. By changing either of these things, you will end up with different button layouts.
As I recall, customizing the ButtonBar was kind of tricky. You might need to subclass the alert and override createButtonBar.
What I try to accomplish, is the button order Yes - No - Cancel. Any advice?
My advice is: Don't try to customize the button order, but let the system default order be applied. The button order has already been preconfigured to match the standard button layout for dialogs for various operating systems. Reordering the buttons to deviate from that standard may make your application just slightly more confusing for users (that's a pretty subjective opinion though).
This is a modified version of #Adam solution. Advantage - no need in extra class, no need to remove existing dialog pane with all its content.
ButtonBar buttonBar = (ButtonBar) alert.getDialogPane().lookup(".button-bar");
buttonBar.setButtonOrder(ButtonBar.BUTTON_ORDER_NONE);

If statement in QF-test

I am learning QF-test and want to do a simple if statement. If I make a change on this one page it enabled an "Apply" button that I want to click if it becomes enabled.
When I check if the button is enabled this is what appears
Check boolean: enabled (true) [buttonApply=>($client)]
So I want to say something like
if 'buttonApply.enabled'=="true"
Mouse Click [buttonApply=>($client)]
but that doesn't seem to work
Well I emailed QF-test support and got this answer
Set the variable in the field 'Variable for Result'. Let's say 'CompPresence'
When you run the script , the variable 'CompPresence' will be filled with the value 'true' if the button "Apply" is enabled.
You can use the If loop like If '$(CompPresence)'==”true”

Interacting with VB6 client using hidden control in embedded web browser control

I'm having difficulty trapping a programmatically triggered click event on a hidden button control from a ASP.NET MVC 4 web app inside a VB6 thick client (which is using a web browser control). I'm able to trap the click event itself using the following:
Private WithEvents WebDoc As HTMLDocument
Private Function WebDoc_onclick() As Boolean
Select Case WebDoc.activeElement.iD
Case "A"
Do something
Case "C"
Do something else
End Select
WebDoc_onclick = True
End Function
And this works just fine if the control is visible. But if the control is invisible:
<div class="HideBtnDiv">
<input id="C" name="NoItems" type="button" class="BtnDiv" style="display:none"/>
</div>
and I try to trigger a programmatic click via one of the following:
$("#C").('click');
$("#C").trigger('click');
$("#C").triggerhandler("click");
$("#C").focus();
$("#C").trigger('click');
I'm getting an empty string for the "id" attribute and as a result I can't distinguish which button was clicked. This button serves no purpose other than to indicate to the VB6 app that a certain criteria has been met and that's the reason why I need it to be hidden. Does anyone have any idea why the id is getting stripped? Or is there any other way to communicate back to the client?
I've also tried filtering by element style using
Select Case WebDoc.activeElement.Style
Case "display:none"
Do something else
End Select
but it came back as "[Object]" so no luck there either. Please let me know if there is a way around this.
Thanks,
Lijin
You seem to have tried several ways of dynamically triggering the click event, but did you try the most obvious way:
$("#C").click();
???
But here is what I would do:
1- Make all of your buttons visible, by removing "display:none" from their style
2- Wrap the buttons you want to hide in a new DIV
3- Set "display:none" style in the newly created DIV
4- You can then trigger the .click() event of any button even if not visible by calling $(id).click();
Thanks, Ahmad. Actually I meant .click() not .('click'). Sorry about that.
Anyway, I tried your suggestion and made the button visible and set the style of the wrapping div to display:none but the id attribute was still coming through as an empty string.
However, I did figure out another way to get this to work. If I keep the wrapping div and button as visible and then focus and click when the condition is met and then do a hide(), my problem is resolved!
$("#C").focus();
$("#C").trigger('click');
$("#C").hide();
The button doesn't get displayed and VB6 still passes the id on the click event. The weird thing is it requires the focus() call to still be made. Without it, I'm back to square one. Not sure if this is a bug.

How can I validate my Firefox extension's preferences?

What is a generally accepted way to validate preference values in a Firefox extension, specifically when using the prefwindow mechanism in XUL?
I am introducing some new preferences in one of my extensions that I would like to validate before the preferences window is closed. If there's an error, the user should be allowed to correct the issue, and then proceed. I see that the prefwindow element has two potentially useful functions to help in this regard:
onbeforeaccept
ondialogaccept
The former seems to have an associated bug (Bug 474527) that prevents the prefwindow from remaining open when returning false from that function. This is bad in that it doesn't give the user an opportunity to immediately correct their mistake.
The latter appears to have the problem that the preferences get saved prior to exiting, which leaves the preferences in a bad state internally.
In addition, the prefwindow mechanism supports the browser.preferences.instantApply option, in which preference values are written immediately upon updating the associated control. This makes validation extra tricky. Is there a clean way to validate custom preferences in a Firefox extension, allowing the user to correct any potential mistakes?
Normally you would want to validate the preferences when they are changed. That's something that onchange attribute (and the corresponding change event) is good for:
<preference name="preference.name" onchange="validate(this);"/>
The event is fired after the preference value changes. There are two drawbacks:
In case of instantApply the new preference value is already saved, too late to validate and decline.
For text fields the preferences are saved every time a new character is typed. This becomes ugly if you report validation failure while the user is still typing.
You can solve the first issue by intercepting the change events for the actual input fields. For example, for a text field you would do:
<input preference="preference.name"
oninput="if (!validate(this)) event.stopPropagation();"
onchange="if (!validate(this)) { event.stopPropagation(); this.focus(); }"/>
So changes that don't validate correctly don't bubble up to the <prefpane> element and don't get saved. The events to listen to are: input and change for text fields, command for buttons and checkboxes, select for the <colorpicker> element.
The second issue is tricky. You still want to validate the input when it happens, showing the message immediately would be bad UI however. I think that the best solution is to assume for each input field initially that it is still "in progress". You would only set a flag that the value is complete when you first see a blur event on the field. That's when you can show a validation message if necessary (ideally red text showing up in your preference page, not a modal prompt).
So to indicate what the final solution might look like (untested code but I used something like that in the past):
<description id="error" hidden="true">Invalid preference value</description>
<input preference="preference.name"
_errorText="error"
onblur="validate(event);"
oninput="validate(event);"
onchange="validate(event);/>
<script>
function validate(event)
{
// Perform actual validation
var field = event.target;
var valid = isValid(field);
// If this is the blur event then the element is no longer "in progress"
if (event.type == "blur")
{
field._inputDone = true;
if (!valid)
field.focus();
}
// Prevent preferences changing to invalid value
if (!valid)
event.stopPropagation();
// Show or hide error text
var errorText = document.getElementById(field.getAttribute("_errorText"));
errorText.hidden = valid || !field._inputDone;
}
</script>
If you want to validate values as soon as the field is changed so you can handle the instantApply case, you could hook into the change events for the individual fields (e.g. oninput for a textbox). Display an error message and force the focus back to the field if the value is invalid. You can either set it back to a valid value automatically or block the user from closing the dialog until it is fixed.

Navigating through widgets using the TAB key

What should I do in order to allow users to navigate through widgets using the Tab key (in either Gtk or any derivative like gtkmm, pyGtk)?
This is build into the default "key_press_event" signal handler. If you set your own handler you must return FALSE from this handler because a TRUE means you have handled the key and no further processing is done. You can use this to avoid the default tabbing.
And i would like to add a question here, because i have no idea how i can do the focus-next-widget, focus-prev-widget action programmatically.
Is tabbing through your controls not working? This should work out of the box as you build up your forms. To customize the order of moving through the widgets as you tab, you use the set_focus_chain methods: gtk, pygtk, gtkmm.

Resources