Is there an easy way to force users to enter numbers only in a Xpages editbox? Other than validating the field after the fact that is. I don't want them to be able to enter a number at all.
You can add client-side Javascript handling such as what has been suggested here:
HTML Text Input allow only Numeric input
You write below code in a Xpages editbox on event onkeypress
if (event.keyCode >= 48 && event.keyCode <= 57)
{
event.returnValue = true;
}
else
{
event.returnValue = false;
}
This code will force user to enter numbers only.
You can add validation and formatting of numbers using the built in dojo.number class: http://dojotoolkit.org/api/1.6/dojo/number/format and make use of the dojo.form widgets.
If you're running on a mobile web platform (iOS or Android) then you should also think about setting the type of the field to number so that the platform itself will add another level of protection.
Matt
extlib / upgrade pack1 has editors with formatting rules.
Related
I have 2 editable text web parts on a page. One web part has default text set on it as the majority of the time it will be the same text.
I want to set visibility of this web part based on the text of another web part for the live site.
I tried this:
{#!string.IsNullOrEmpty(WebPart.GetValue("AreaDescription", "Content")) &&
CMS.PortalEngine.ViewModeEnum.LiveSite == CMS.PortalEngine.PortalContext.ViewMode #}
But then it's never visible so it's not picking up the text inside the other webpart successfully. So I'm thinking maybe I need to call GetContent() to get the user provided text of the editable region. I tried writing a custom transformation method but using the below - PagePlaceholder is unknown and I'm not sure how to get a reference to it.
CMSAbstractWebPart webpart = PagePlaceholder.FindWebPart("webPartId");
Try {% (ViewMode == "LiveSite") && (CMSContext.CurrentDocument.WebPartID != "") #%}
in a macro to get the content of editable text:
{%CurrentDocument.DocumentContent["webPartId"]#%}
so what you are looking for is something like this:
{%!string.IsNullOrEmpty(CurrentDocument.DocumentContent["AreaDescription"]) && (PortalContext.ViewMode == "LiveSite")#%}
From Kentico support - macros will not allow me to do what I want to achieve because content of other web parts is not available in CMSContext or in DocumentContent.
As I was trying to avoid custom web parts they suggested I could create an alternative layout for my web part that would be the same as default plus add:
your handler for onLoad, or any better event
If it was a custom web part I could add:
///find another web part - in this case WebPart1
CMSAbstractWebPart webpart1 = PagePlaceholder.FindWebPart("WebPart1");
///store value/content of chosen property
string wp1DefaultText = ValidationHelper.GetString(webpart1.GetValue("DefaultText"), "");
Potentially on Prerender to ensure it wouldn't be overridden.
At this stage I'm just going to remove the default text as it feels like I'm fighting the system and the value gained probably isn't worth the effort/customisation.
I’m developing web app using Primefaces and one of the requirements is that hotkeys should work. And they do but there is a catch. While reading documentation I found out that hotkeys hotkey will not be triggered if there is a focused input on page. And this is big show stopper for us. Is there a way to make at least some hotkeys like F1, F2, ESC etc. work?
One way to achieve that is to manually bind the hotkeys to the inputs you choose.
I don't know your personal needs, but the following code (in jQuery) will bind it to all input, textarea, select and button elements.
$(':input').keydown(function (event) {
if (event.which == 112) { //you could also make a switch :)
alert('f1 pressed!'); //do what you want
}
if (event.which == 113) {
alert('f2 pressed!'); //do what you want
}
//...
})
Also don't delete your p:hotkeyto continue with its normal behavior.
Note: Search for javascript keycode if you want to know more codes.
There is a viewPanel having a column with showCheckbox="true".
Is it possible to restrict the users to select only one row/document ( and not multiple rows/docs. ) listed by the viewPanel?
Not in a View Panel. The View Panel is designed to offer a quick, simple approach with restricted functionality.
An alternative (possibly better) approach may be to have another column with a link or image that triggers whatever functionality you need. That will allow users to trigger functionality with a single click rather than two. The View Panel allows you to place controls in columns instead of just mapping to a column in the underlying view.
Alternatively, you could add a checkbox manually to a column, map to a scoped variable, and check/uncheck programmatically.
Paul's probably right on. My alternative for you is to use a repeat control. You can make it look however you want. Including a view control.
I have an example of this in this NotesIn9 show: http://notesin9.com/index.php/2011/07/11/notesin9-ee-009-using-java-hashmaps-and-treemaps-with-xpages/
Now in my example I did multiple values. But if instead of a HashMap or ArrayList if you kept your "selected" document id in a single value field like just a scoped variable.. then you'd get what you want. One document at a time.
I agree with Paul Stephans (also upvoted his answer because I think it would be the Nest solution) but if you insist on adding such a functionality to your viewPanel you can do this by adding a client side script to prevent the user from selecting more then one element:
First add the styleClass="rowCB" to your checkbox row and insert this code to your xpage:
<xp:scriptBlock>
<xp:this.value><![CDATA[dojo.ready(function(){
dojo.query('.rowCB>input').connect("onclick", function(evt){
var target = evt.target.id;
if(!window.crrCheckedElement){
window.crrCheckedElement = evt.target.id;
}else if(window.crrCheckedElement != target){
alert("You can select only one item!");
evt.target.checked = false;
}else if(window.crrCheckedElement == target){
window.crrCheckedElement = "";
}
})
});]]></xp:this.value>
</xp:scriptBlock>
Maby the code needs some improvement but this should be your way to go.
though maybe not the best solution, here is one possibility.
function deselectOtherDocs(viewName, currentDocId) {
var viewPanel:com.ibm.xsp.component.xp.XspViewPanel = getComponent(viewName);
var selectedIds = viewPanel.getSelectedIds();
for(var i=0; i<selectedIds.length; ++i){
if(selectedIds[i]!=currentDocId){viewPanel._xspSetIdUnchecked(selectedIds[i])}
return;
}
fire this off when a doc is checked and pass the view control name and the current doc's unid.
pardon any typos. I am writing from my phone.
edit: if you don't have to use a view control, then David Leedy's suggestion is the way to go. store the selected unid in a scope variable and let that determine which repeat row's box is selected. you might also consider using a radio button instead of a checkbox, since the former is understood as a single selector by users.
Using Lwuit Version 1.5, Im having a problem using the Virtual Keyboard.
Given a TextField with a Numeric constraint.
The first character entered will go directly to the Textfield despite the constraint given.
I´ve found the sourceCode in actionCommand on VirtualKeyboard.java producing this issue;
case INSERT_CHAR:
Button btn = currentButton;
String text = btn.getText();
if (inputField.getText().length() == 0) {
inputField.setText(text);
inputField.setCursorPosition(text.length());
} else {
inputField.insertChars(text);
}
break;
As seen above the first character will never go through insertChars and check for validity later.
Question is: I can't figure out why is this behavior implemented, Im afraid to break something I don't realize if I override that deleting the "if" part.
Anyone knows what the reason could be?
If anyone already have a Workarround for this issue please Id appreciate.
Its a known bug in LWUIT 1.5 that we fixed in Codename One, unfortunately no one is maintaining LWUIT anymore.
Your options are either to live with this issue, patch LWUIT, use TextArea (which is pretty different) or migrate to Codename One.
I have dojo validation textbox in my xpage with required property computed (compute dynamically) as below
var syn = getComponent("SynCboxGrp").getValue();
if (syn == "Yes")
{return true;
}else{
return false;
}
Here the component SynCboxGrp is radio button. The text box is required based on the radio button value. But its not working properly. Changing radio button value doesnt change the required behaviour.
Appreciate any help
Update
Thanks stwissel, Per Henrik Lausten and Eric.
I only have this ssjs in required property
<xe:djValidationTextBox id="UBOCAgent" value="#{dsRacDoc.UBOCAgent}" disableClientSideValidation="true">
<xe:this.required><![CDATA[#{javascript:var syn = getComponent("SynCboxGrp").getValue();
if (syn == "Yes")
{
return true;
}else{
return false;
}
}]]></xe:this.required>
</xe:djValidationTextBox>
I also tried this partial refresh code on my radio button onclick event XSP.partialRefreshGet("#{id:UBOCAgent}");
This still doesnt change the behaviour. It works based on the initial radio button value. On the negative side since its a get request it updates the field content from the server. I also tried Eric's suggestion disable client validation but that didnt help.
Eric, I am also trying to go with CSJS wherever possible but in this case the required property only has the SSJS option. So not sure how to try CSJS. Should i try creating my own dojo field instead of using one from entension lib? If so i am not sure how to compute required property for that. If you can help me with some sample code that would be great help.
Thanks for your time.
You're doing a partialRefreshGet, which is updating the Dojo Validation Text Box. But you never post back the updated value from the radio, so the server-side value for the radio button is still the initial value. Consequently, required is still false.
Check the markup when required is true on the Dojo Validation Text Box, but the validation triggers client-side, so there should be an attribute in the markup that you can manipulate via CSJS, if that is your preferred route.
Do you have particular latency issues that you need to work around? Picking up on this and the other question you have about doing a lookup to a database on click of a button, you're hitting a few problems. I don't know how experienced you are in XPages development, but it's not an approach I would recommend without a good understanding of client-side output and server-side component trees. The initial page load of your XPage will also be slower and the size of the HTML passed to the browser will be larger, because of the amount of CSJS passed to the browser.
I would recommend using the in-built partial refresh except for situations where browser to server network is a significant issue, and only then falling back to coding your own partial refresh posting a subset of data. In my experience, it's easier and quicker to develop, easier to debug and more flexible.
For this particular scenario, regardless of whether you code the partial refresh yourself or use inbuilt functionality, one point I'm not certain of is this. That once you set validation on the Dojo Validation Text Box, that validation runs client-side and may impact any attempt to un-set the required property by posting to the server. I haven't tested, so can't be certain.
One of two things:
as previously mentioned, to trigger your SSJS value change, ensure a partial (at least) refresh of the element containing your above code; can be done with a container element. Also, check to see if your field's disableClientSideValidation parameter is set (All Properties view).
convert your SSJS code (which merely returns a binary assessment of a Yes or otherwise, I'm assuming No, value) to CSJS
Of late, after the primary development of my current project, I have started favoring the CSJS approach, for the sake of decreasing server-side call backs; most especially in situations where display/rendering of a component is all I'm trying to achieve. If you go this route, remember that dojo.byId("#{id:myControlsServerNameHere}").value (for a text field, see below for scraping a radio button value) combined with setting the display or visible CSS properties can be very handy. As the docs describe, if you want it to exist on the page but not show (for formatting purposes, also, can preserve default value), go the visibility route, otherwise display property.
The CSJS scrape of radio values that I'm currently using is as follows:
var result=null;
for(i=0; i<document.forms[0].elements.length;i++){
if(document.forms[0].elements[i].name=="#{id:serverNameOfRadioElement}"){
if(document.forms[0].elements[i].checked == true){
result=document.forms[0].elements[i].value;
break;
}
}
}
//then handle your result, either with an if, or switch statement
Hope this helps. If there's more you're having trouble with, post back with more code to give the bigger picture.