Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Hide and show button at the top or at the end of the form

Avatar

Former Community Member

Hi,

I have the form that has 2 buttons, move up and move down, which is used to move the subform up or down. I currently have it to pop up a message: "The current item can't be moved up" when the user try to move that item up since they are already at the top of the form

or "The current item can't be moved down" since they are already at the bottom of the form.

Now I'd like to have one to be hidden depend on where on the current location instead of the pop up message.

Can any one please advise.

Thanks in advance,

Han Dao

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Here is the form back to you: https://acrobat.com/#d=tO5CEU86asS5yBXTFDilpg.

There was script in the layout:ready event that was not needed and causing the loop.

Also I have amended the structure slightly, the Question number script and added an execEvent() line to the click event of the add button. I would be careful of using names that may be reserved.

Hope that helps,

Niall

View solution in original post

8 Replies

Avatar

Level 10

Hi Han,

You could achieve this, but it would require script in the layout:ready event, which will have a hit on performance. Basically it would be similar to what you are doing now with the moveInstance and messageBox. You would compare the current index of the row containing the button, if this is "0", then hide the up button. If the index is equal to the count-1, then hide the down button.

Bruce has a good alternative to using the layout:ready event when working with repeating rows, by declaring a variable with the count in the calculate event. This will then fire everytime a new row is added, without firing constantly. However I don;t think that approach will work here, as the moveInstance won't cause the calculate event to fire.

I have an example here where I give visual feedback (button goes red if the row can't be moved in the required direction / green if it can) and audio feedback (beep if the row can't be moved).

Acrobat2.png

http://assure.ly/oF9SrB

Let me know what you think.

Niall

Avatar

Former Community Member

Hi Naill,

Here is the code that I try to place in the layout:ready event but it does not seem to work. Can you please take a look at it.

==============The Code=============

form1990.Questions.MoveSub.up::ready:layout - (JavaScript, client)

//Move Up
if (xfa.resolveNode("form1990.Questions").index != 0) {
  var nIndexFrom = xfa.resolveNode("form1990.Questions").index;
  var nIndexTo = xfa.resolveNode("form1990.Questions").index - 1;
  _Questions.moveInstance(nIndexFrom, nIndexTo);
  xfa.form.recalculate(true);
} else {
// set the button to hide at the top of the form.
  xfa.resolveNode("form1990.Questions.MoveSub.up").presence = "hidden";
}

form1990.Questions.MoveSub.down::ready:layout - (JavaScript, client)

//Move Down
var nIndex = form1990.Questions.index;
if ((nIndex + 1) < _form1990.Questions.count)
{
var nIndexFrom = nIndex;
var nIndexTo = nIndex + 1;
_form1990.Questions.moveInstance(nIndexFrom, nIndexTo);
xfa.form.recalculate(true);
}
else
{
  xfa.resolveNode("form1990.Questions.MoveSub.down").presence = "invisible";
}
===========End ========

Thanks,

Han Dao

Avatar

Level 10

Hi Han,

I have had a think about this and I have worked up an approach, where there is script in the initialize event and the click event of both the Up and Down button.

// Script to move the row

var nIndexFrom = Row1.index;

var nIndexTo = Row1.index - 1;    

_Row1.moveInstance(nIndexFrom, nIndexTo);    


// Script to hide the first Up button and last Down button

// First show all buttons

var nRows = xfa.resolveNodes("Row1[*]");

for (var i=0; i<nRows.length; i++)

{

     nRows.item(i).buttons.moveUp.presence = "visible";

     nRows.item(i).buttons.moveDown.presence = "visible";

}

// Then hide Up button

nRows.item(0).buttons.moveUp.presence = "invisible";


// Then hide Down button

nRows.item(nRows.length-1).buttons.moveDown.presence = "invisible";

This gets away from the layout:ready event so should not hit performance too badly.

The updated example is here: http://assure.ly/oF9SrB.

Hope that helps,

Niall

Avatar

Former Community Member

Hi Niall,

Thanks for the quick reply.

I tried to apply the same technique to the form but it seems to run with an infinite loop which keeps running and does not work right. The attachment is no longer available in the forumn, can I send you a copy of my form for you to review? If so, can you please provide your email.


Thanks,

Han

Avatar

Level 10

Hi,

Something must be off with the references or something like that.

If you upload the form to a file sharing site like Acrobat.com, publish it and then share the published link here, I will try and have a look at it when I can.

In the meantime, try opening the JavaScript Console (Control+J) in Acrobat and then adding rows, see does an error show up in the Console.

Niall

Avatar

Former Community Member

Hi Nial,

I have uploaded the form on Acrobat.com and here is the link.

https://acrobat.com/#d=yhUlRKl76CrdMBEQhFjXqA

I think the script may conflict with the add row script but I could not fix. Please review it and let me know how I can fix it.


Thanks alot in advance,

Han Dao

Avatar

Correct answer by
Level 10

Hi,

Here is the form back to you: https://acrobat.com/#d=tO5CEU86asS5yBXTFDilpg.

There was script in the layout:ready event that was not needed and causing the loop.

Also I have amended the structure slightly, the Question number script and added an execEvent() line to the click event of the add button. I would be careful of using names that may be reserved.

Hope that helps,

Niall

Avatar

Former Community Member

It really WORKS.  Thanks for catching the extra script in layout event that I thought I already removed it. Well, sometimes we may overlook the code but extra pair of eyes have always helped.

Thank you again, Niall.

Han Dao