JSF: Create a "dummy" button which does nothing? - jsf

In our JSF web application, we have an input field where the user can enter a numeric ID, which is then looked up by the app. To help the user, the lookup is bound to "onchange", thus it will be triggered as soon as the user tabs out of the field or clicks elsewhere.
So, user enters "123", presses tab (or clicks), lookup runs. This works fine; however, for usability reasons, we also want to provide a button that users can click on, for users who will otherwise wonder "where should I click to trigger a lookup?". To do this, we'd like to provide something that looks and feels like a HTML / JSF button, but does nothing (as the click will trigger the "onchange" event anyway).
Is there a way to make a JSF button that does nothing? I tried using h:commandButton without the "action" attribute, but it still fires a request.

p:commandButton type="button" will just provide a push button.

Since you tagged this question also as a usability issue, I would advise against a button in the first place if the onchange already triggers the lookup.
From a user's perspective it is confusing whether or not clicking the button is mandatory. After they have entered the field and skipped to the next, they see the lookup occur without clicking the button. If there is a button they will assume it's there for a reason.
The option that I favour in these cases is a onkeypress handler with a timeout of half a second, after which the value is looked up.

Related

How to disable the whole page?

I have a field where a customer number is required. When the user leaves the field in the onblur event I need to run some code, in this case check if the given number is already in use. The problem is the codes needs some time to complete. For this short period the user should not be able to make any input. Also I'd like to display a gif.
There is a genius snippet on XSnippets called "Standby Dialog" (https://openntf.org/XSnippets.nsf/snippet.xsp?id=standby-dialog-custom-control)
If you implement this on your page (preferably as custom control) you will get an overlay everytime a partial refresh happens. If you init a partial refresh when the user blurs the field you will get what you want.

XSP.partialRefresh does not fire after XSP.confirm

Short overview of my issue: I have a large form with several fields, one of them is a xe:djFilteringSelect and one a xp:combobox. The xp:combobox is computet depending on the value selected in the filtering select. Now my customers want that if they change the value of the filtering select of a already saved docoument they should be prompted with a warning. So i want to add a confirm message to the onChange event of the djfilteringselect to cancel it's SSJS code wich changes the combobox.
Prompting the user with a confirm ("change value?...") box is no big deal but reseting the value back (on ClientSide) if the users selects "no" gives me a lot of trouble.
What i have already tryed:
If i use a simple confirm action all further onChange actions get canceled but the djFilteringSelect field keeps it's user selected value. So if i fire a partial refresh on the filtering select the original value form the document is displayed but i don't know where to add it because there is no onCancel or did i miss something here?
I also tried it from the CSJS with window.confirm and XSP.confirm and reset the value manual with a XSP.partialrefreshGet() if the user selects 'no' but in this case the partial refresh does not work:
if(!XSP.confirm("execute?")){
XSP.partialRefreshGet("#{id:repeat1}",{
onStart: function () {console.log("start");},
onComplete: function () {console.log("finish");},
onError: function () {console.log("error");}
});
return false;
}
If i move the partial refresh to a function and call it from e.g. firebug it works fine but if i call it inside the if(confirm){} it does nothing at all. The return false does work the SSJS does not get executed. The value in the document is not changed (as intended), but the djFilteringSelect keeps the selected value on the ClientSide.
I also tried Mark Leusink´s dojo-style Confirm but same Problem with the partial refresh here.
If i set the value back manual instead of using a partial refresh with dijit.byId(item).setValue it will resoult in another onChange Event... loop. Update: If i use dijit.byId(item).set("value",newVal,false) the onChange does not fire direct it changes the value as intended but then the onChange fires when the filtering select looses ist ??focus!?!? ...
So my questions:
Is there a ways to execute any Code after the confirm action if the user selects "no".
Why is the partial refresh in my CSJS not working (i dont see any traffic in firebug and i dont get any errors not even the onError of the refresh gets fired).
Does anyone know a different approach to my problem?
update:
My current 'solution' is to use window.location.reload() instead of the XSP.partialRefresh to reload the site. But this solution does not really satisfy me, because in IE the whole page is flickering.. in firfox i can live with it.

CRM 2011 Sub-Grid: Call JavaScript On-Click or On-Focus

How can JavaScript execute when a sub-grid receives focus?
I have a sub-grid that shows all Cases associated with an Account.
I would like to disable some fields on the form when the sub-grid receives focus.
RibbonDiffXML action for a ribbon button:
<Actions>
<JavaScriptFunction Library="$webresource:mda_convertemailtocaselib" FunctionName="ConvertEmailToCaseLib.addToCase">
<CrmParameter Value="SelectedControlSelectedItemIds" />
</JavaScriptFunction>
</Actions>
This passes the sub-grid select items to a ribbon button, but I would like the JavaScript to execute before the ribbon button is pressed.
I haven't tried either of these out, but hopefully one of them should work for you.
Although it is a subgrid, there still is a control on the form. Unfortunately there is no "supported" way to know when a control gets focus since there aren't any OnFocus/OnBlur methods exposed via the CRM JS API. However you should be able to add your own JS event handler for that control and disabled the fields via the API Xrm.Page.getControl("fieldname").setDisabled(true)
I'm not 100% sure if this way would work, but it would be pretty sweet. Create a CustomRule EnableRule. In this CustomRule you call your own JS. In this create a function where you disable the fields and then return true to make the button enabled. It would look something like this:
function disableFieldsEnableRule() {
Xrm.Page.getControl().setDisabled(true);
...
...
return true; // so the button is enabled
}
The only reason I'm not sure if this will work is because I'm not sure if the Enable rules are checked each time you click on the subgrid or just the first time (I think it should be every time). Also I'm not sure if you want those fields re-enabled once you click off. If you do you might have to do something similar to this with a button on the native form, or something else.

How can I know what form control had focus when ribbon button pressed?

Have a custom JS function that gets called when a ribbon button is pressed in the context of a form. In my custom JS function I need to know what form field had the focus just prior to the ribbon button being pressed. I've tried 2 ways (below) without success. Is there any way to do this reliably?
Way #1
According to this, I can get the control I want passed as a parameter to my JS. I've tried using both PrimaryControlId and PrimaryControl parameters.
<JavaScriptFunction FunctionName="OnCustomBtnFunc"
Library="$webresource:myJSfile.js">
<CrmParameter Value="PrimaryControlId" />
<CrmParameter Value="PrimaryControl" />
</JavaScriptFunction>
For both, I get an object passed to OnCustomBtnFunc() but it does not seem to enable me to determine which form control had the focus prior to the ribbon button being pressed.
Way #2
I call Xrm.Page.ui.getCurrentControl(). This works for form fields of some types but not others e.g. if it is a string field it works but I get null for a lookup.
you won't like this answer, but you can use JQuery to quickly grab every Control in your Form and assign it an OnBlur event. This event can either assign the ID or the control itself to global variable, which you will make accessible to your ribbon (which fires from a different scope).
People do not like this approach because of the different context scopes of the variables and because it involves playing with "unsupported" features of plain HTML. However, if you ask only the question "how" and not "should we", then this is an easy way for "how" you would do this.

Using `immediate` for a cancel button but saving only some fields

I have a JSF 1.2 Form which is composed of several parts.
I have validation with required tag turned on.
I want to be able to clear a certain part of the form which has required fields so on the 'clear' button i used the immediate tag.
Now the challenge - When pressing the 'clear' button all the values that were filled since the last submission are restored to the last submitted state while I would like only the certain part of the form to be affected. (Meaning, all the values that are not in that part of the form should be sumbitted although the button pressed is immediate)
Is there a way to do this?
EDIT - Can I submit a value after every time it was filled? This might be a solution.
Thanks!
If you want to take some fields along with the cancel button with immediate="true", then you should also put immediate="true" on those fields.
If you want to skip validation on those fields as well, then you need to change required="true" to required="#{empty param['formId:cancelButtonId']}" so that it is only required when the cancel button is not been used to submit the form.
As to submitting the values on change, that's best to be achieved with ajax in combination with a value change listener. To achieve that you would need to upgrade to JSF 2.0 or to introduce an ajaxified JSF component library.

Resources