1

How could i add currency constraint to djxDataGridColumn in Dojo layout

Programmaticly i will use:

{ name: 'Amount', field: 'col5', formatter: formatCurrency, constraint: {currency: 'EUR'}, widgetClass: HorizontalSlider, width: 10}

But how can i make it happen in XPages:

<xe:djxDataGridColumn id="djxDataGridColumn10" editable="true" label="Amount " field="Amount " width="50px" cellType="dojox.grid.cells._widget"
formatter="formatCurrency">
</xe:djxDataGridColumn>

I need to be able to validate the Column input when the grid is edited

function formatCurrency(value){
        return isNaN(value) ? '...' : currency.format(value, {currency: "EUR"});
    }

Error message when String is entered Error message when String is entered

simon peter
  • 403
  • 8
  • 19
  • Can you add more general information on what you are doing? I am a confused where the user puts input in the grid, especially since your column is set as editable="false". – Steve Zavocki Dec 02 '15 at 13:44
  • editable="true". i have update above, i want the cell to accept only numbers or fraction and no string – simon peter Dec 02 '15 at 13:58
  • You could just limit the characters that you can type to 0-9 and your decimal separator (. for US, some countries use ,). This is a different approach where the keyboard keys are limited, but the value is not validated. Do you want me to make an answer that shows this? – Steve Zavocki Dec 02 '15 at 14:23
  • yes pls that would be great – simon peter Dec 02 '15 at 14:37

2 Answers2

1

Define your column without cellType property

  <xe:djxDataGridColumn
     id="djxDataGridColumn10"
     editable="true"
     label="Amount "
     field="Amount"
     width="50px"
     formatter="formatCurrency">
  </xe:djxDataGridColumn>

and change your CSJS code to

require(["dojo/currency"]);
function formatCurrency(value){
    return isNaN(value) ? '...' : dojo.currency.format(value, {currency: 'EUR'});
}

The constraint {currency: 'EUR'} converts and shows values as EUR currency €:

enter image description here

In case the value is not valid it shows "...".

Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
0

Simon,

You can limit the keyboard keys the user is allowed to type which prevent them from entering alphabetic characters. This option doesn't validate the numeric content, you would have to do that separately if needed.

You will need to create a clientside function that acts on the onkeypress event.

The code will look similar to this:

var keyCode = event.keyCode;
if((keyCode >= 48 && keyCode <= 57) || keyCode == 8 || keyCode == 46){
   event.returnValue = true;
}else{
   event.returnValue = false;
}

This example allow numbers as well as backspace and delete. If you want to allow a fraction separator then modify this to allow it. An easy way to find the keycode is using http://keycode.info/

Here is a blog post I wrote last month on this subject: http://notesspeak.blogspot.com/2015/11/limiting-keyboard-input-in-xpages.html

Despite the blog post title, this is just clientside javascript and not specific to XPages. You can also use dojo or jQuery to accomplish the same thing.

Steve Zavocki
  • 1,840
  • 4
  • 21
  • 35