Page 1 of 2

Conditional editing for output fields?

Posted: Wed Jan 28, 2015 4:51 pm
by rmarsh
One can replace the value property of an output field with a static value such as "Master Files"
The issue is on a dynamic menu where the value can change I cannot simply use a static value. What I would like to do is change "Master Files.........." to "Master Files" by somehow removing the ".........."

Can this be done?

Thanks.

Re: Conditional editing for output fields?

Posted: Wed Jan 28, 2015 5:08 pm
by Alex
On a specific field and property, you can specify "js:" or "script:" followed by a JavaScript expression. For example, the following replaces all dots in a field with empty spaces:

Code: Select all

js: value.replace(/\./g, "");
If you need to do this globally on a screen (or on all screens within an application), you could write a script to loop through all fields on the screen and do the replacement. This would normally go into your custom.js file. The code for something like that would look as follows:

Code: Select all

var fields = getOutputFields();
for (var i = 0; i < fields.length; i++) {
  var field = fields[i];
  var value = get(field.id);
  value = value.replace(/\./g, "");
  pui.set(field.id, value);
}

Re: Conditional editing for output fields?

Posted: Wed Jan 28, 2015 5:16 pm
by rmarsh
That worked great. I entered the second example code in the onload property of the screen. Is that the best way to do this?

Re: Conditional editing for output fields?

Posted: Wed Jan 28, 2015 5:27 pm
by Alex
Putting into the onload event should work without problems.

But if you needed to make this reusable for other screens, you could put the code into cusotm.js as a function, like this:

Code: Select all

function replaceDots() {
  var fields = getOutputFields();
  for (var i = 0; i < fields.length; i++) {
    var field = fields[i];
    var value = get(field.id);
    value = value.replace(/\./g, "");
    pui.set(field.id, value);
  }
}
The in the onload event, you would simply specify:

Code: Select all

replaceDots();
Your custom.js file is located in the following IFS directory: /www/profoundui/htdocs/profoundui/userdata/genie skins/[The Name Of Your Skin]

Re: Conditional editing for output fields?

Posted: Wed Jan 28, 2015 6:41 pm
by rmarsh
Thanks again Alex.

I am noticing some changes in areas where there are no dots. For example text fields that were centered are now left justified. As if the spaces were removed. Also, the sub-file border only in the center of the screen went from solid blocks to underscores.
Before replacedots
Before replacedots
InfiniumBeforeNoDots.JPG (73.95 KiB) Viewed 4407 times
After replacedots
After replacedots
InfiniumAfterNoDots.JPG (88.67 KiB) Viewed 4407 times

Re: Conditional editing for output fields?

Posted: Wed Jan 28, 2015 8:11 pm
by Alex
Our get() API trims blanks spaces. Try using getElementValue() instead of get(). That should not trim the spaces.

Here are the docs for these API:
http://www.profoundlogic.com/docs/displ ... %28+id+%29
http://www.profoundlogic.com/docs/displ ... %28+id+%29

Re: Conditional editing for output fields?

Posted: Thu Jan 29, 2015 11:49 am
by rmarsh
Thanks again Alex.

It is still doing the same thing. I've played around with various methods and I can get js to replace a '.' with a space in a string but not in 5250 output field. I don't know why the behavior is different. It still is replacing leading blanks and changing part of the subfile boundry. Those areas have no dots so I'm not sure what is going on there.

Re: Conditional editing for output fields?

Posted: Thu Jan 29, 2015 12:10 pm
by Scott Klement
Ray, can you post your modified version of replaceDots() so we can see what it looks like now?

Re: Conditional editing for output fields?

Posted: Thu Jan 29, 2015 2:27 pm
by rmarsh
The "if" statement is to target only specific output fields on the screen. I'm not sure it is still necessary but this is working.

Code: Select all

function replaceiDots() {
  var fields = getOutputFields();
  for (var i = 0; i < fields.length; i++) {
    var field = fields[i];
    var str = field.id;
    if ((str.split("_")[2] == "43") || (str.split("_")[2] == "4")) {
      fields[i].innerHTML=fields[i].innerHTML.replace(/\&nbsp;\./mgi,"&nbsp;&nbsp;");
    }
  }
}

Re: Conditional editing for output fields?

Posted: Thu Jan 29, 2015 9:23 pm
by Alex
It's not apparent to me what the problem might be. It seems like your version of the code should work. Perhaps you could post a JSON capture of your screen here, so that we can try it on our system. To get the capture, navigate to the screen and press Ctrl-F9. Thanks.