Is there a function I could use to pad a text string with spaces?
I need to take input of a numeric value, which could be anything from 3 to 6 digits but then I need to right justify that value in a text field, i.e. turning 1001 into ’ 1001’
I’ve taken a look through the available string functions and nothing jumps out at me. I could write a loop but that seems excessive if i’m overlooking a simpler option.
var spaces = ' ', // 10 spaces, add more if you need more
maxLength = 10; // lets say the max string length is 10
// Now add padding spaces to the left of the value.
myStringColumn = utils.stringLeft(spaces, maxLength - String(myNumberColumn).length) + String(myNumberColumn);
It’s an exact find I’m trying to do, to validate that my form holds a unique value before creating a record. I’ve got there but I don’t really understand the difference!
I had this, which didn’t work;
var spaces = ' ', maxLength = 7;
var lvExtn = utils.stringLeft(spaces, maxLength - String(pExtn).length) + String(pExtn);
controller.find();
extn=lvExtn;
var nResults = controller.search();
So, I studied the find() help and I’ve changed extn=lvExtn; to extn=‘=’+lvExtn; as per one of the examples and now it works but I have other non-exact match finds where I’ve not specified the = in the search string. It’s this type of stuff I’m really struggling to get my head around, very subtle changes can make a big difference.
var spaces = ' ', maxLength = 7;
var lvExtn = utils.stringLeft(spaces, maxLength - String(pExtn).length) + String(pExtn);
controller.find();
extn='='+lvExtn;
var nResults = controller.search();
The reason that you have to use the ‘=’ here is that you are searching for a value that starts with whitespace.
We remove leading/trailing whitespaces because the find can also be used like this from a form by the user (find mode).
If the user accidentally added a space at the front or end a search fail would be unexpected by the user.
The ‘=’ enforces the string to be interpreted as a whole.
Btw, when using find(),always check the boolean result, the UI may be in a state that the find is not possible.