Skip to main content
arnoldg791
October 21, 2021
Solved

How to hide document viewer field once opened?

  • October 21, 2021
  • 8 replies
  • 0 views

Hello everyone!

Im just toggling with the documentViewerField function and would like to know how to hide the documentViewerField once the user clicks on the dynamic field [that opens up the field]. I've tried toggling with the code for a while but was not successful. Any advice, tips, guidance is welcomed [emoticon:c4563cd7d5574777a71c318021cbbcc8]

Code: 

a!localVariables(
  local!documents: {47149, 47150},
  local!link,
  a!forEach(
    items: local!documents,
    expression: {
      a!linkField(
        links: a!dynamicLink(
          label: "Click Here to View File: " & document(documentId: fv!item, propertiy: "name"),
          value: fv!item,
          saveInto: local!link
        )
      ),
      a!documentViewerField(
        document: fv!item,
        showWhen: fv!item = local!link
      )
    }
  )
)

Best answer by mikes0011

I recommend never using a!linkField - you should only use a!richTextDisplayField.  And yes, the second link would go there.

As an example I've rewritten your above code in my own "style"; here we get a list of all documents provided each as their own link, and clicking any of them will open that document in the viewer field below (notice you can click a second document and it will open that one instead).

a!localVariables(
  local!documents: {47149, 47150},
  local!selectedDocId,
  
  a!sectionLayout(
    label: "Section",
    contents: {
      a!richTextDisplayField(
        value: {
          a!forEach(
            items: local!documents,
            expression: {
              a!richTextItem(
                text: "View Document: " & document(fv!item, "name"),
                link: a!dynamicLink(
                  showWhen: tointeger(local!selectedDocId) <> fv!item,
                  saveInto: {
                    a!save(local!selectedDocId, fv!item)
                  }
                )
              ),
              if(fv!isLast, "", char(10))
            }
          )
        }
      ),
      
      a!documentViewerField(
        label: "Selected Document",
        document: local!selectedDocId,
        showWhen: not(isnull(local!selectedDocId)),
      ),
      a!richTextDisplayField(
        showWhen: not(isnull(local!selectedDocId)),
        value: a!richTextItem(
          text: "Hide",
          link: a!dynamicLink(
            saveInto: {
              a!save(
                local!selectedDocId,
                null()
              )
            }
          )
        )
      )
    }
  )
)

Also as a side note, with the Rich Text Display Field, you can do more advanced things based on the selected document ID like changing the formatting of the row(s), hiding the link on the currently-selected row, using different icons, etc.

8 replies

mikes0011
Brainy
October 21, 2021

You create a second link that saves "null()" back into your local variable.  I would suggest you name that variable "local!selectedDocId" instead of "local!link", because "local!link" is misleading among other things.

The Expression Guru
arnoldg791
October 21, 2021

would that second link go inside a!linkField ?

mikes0011
mikes0011Answer
Brainy
October 21, 2021

I recommend never using a!linkField - you should only use a!richTextDisplayField.  And yes, the second link would go there.

As an example I've rewritten your above code in my own "style"; here we get a list of all documents provided each as their own link, and clicking any of them will open that document in the viewer field below (notice you can click a second document and it will open that one instead).

a!localVariables(
  local!documents: {47149, 47150},
  local!selectedDocId,
  
  a!sectionLayout(
    label: "Section",
    contents: {
      a!richTextDisplayField(
        value: {
          a!forEach(
            items: local!documents,
            expression: {
              a!richTextItem(
                text: "View Document: " & document(fv!item, "name"),
                link: a!dynamicLink(
                  showWhen: tointeger(local!selectedDocId) <> fv!item,
                  saveInto: {
                    a!save(local!selectedDocId, fv!item)
                  }
                )
              ),
              if(fv!isLast, "", char(10))
            }
          )
        }
      ),
      
      a!documentViewerField(
        label: "Selected Document",
        document: local!selectedDocId,
        showWhen: not(isnull(local!selectedDocId)),
      ),
      a!richTextDisplayField(
        showWhen: not(isnull(local!selectedDocId)),
        value: a!richTextItem(
          text: "Hide",
          link: a!dynamicLink(
            saveInto: {
              a!save(
                local!selectedDocId,
                null()
              )
            }
          )
        )
      )
    }
  )
)

Also as a side note, with the Rich Text Display Field, you can do more advanced things based on the selected document ID like changing the formatting of the row(s), hiding the link on the currently-selected row, using different icons, etc.

The Expression Guru