Skip to main content
hema.mathivathanan
April 19, 2024
Solved

Interface with auto populating and editing the text field.

  • April 19, 2024
  • 13 replies
  • 0 views

Hello, 

I have a requirement where the text field should get auto-populated based on the previous action. Once the text field is auto populated I have 2 possibilities. 

1. the user can click on submit without making any changes to the text field. In this case, since there is no user interaction, the value is not storing to the saveinto local variable. 

2. the user can change the text field value as per their choice. In this case, the value is saving to the local variable, but it's not reflecting in the text field, since in value parameter there is another local variable.

a!textField(
label: "File Name",
labelPosition: "ABOVE",
value: local!prepopulatedName, 
saveInto: local!docName,
refreshAfter: "UNFOCUS",

),

Here, local!docName is the variable created for storing the value for this text field. 

local!prepopulatedName is the field from where it's getting auto populated. 

Can someone please guide me here?

    Best answer by shubhama926776

     [mention:3670269dff3147e3822f8c49c86782af:e9ed411860ed4f2ba0265705b8793d05] 
    You have to add same code to button saveInto to reflect data into local!docName

    Understand below code and try to implement for yours.
    It will solve your problem.

    a!localVariables(
      local!docName,
      local!prepopulatedName: "Test",
      {
        a!textField(
          label: "File Name",
          labelPosition: "ABOVE",
          value: if(
            a!isNullOrEmpty(local!docName),
            local!prepopulatedName,
            local!docName
          ),
          saveInto: local!docName,
          refreshAfter: "KEYPRESS"
        ),
        a!buttonArrayLayout(
          buttons: {
            a!buttonWidget(
              label: "Button",
              style: "OUTLINE",
              saveInto: a!save(
                local!docName,
                if(
                  a!isNullOrEmpty(local!docName),
                  local!prepopulatedName,
                  local!docName
                )
              )
            )
          },
          align: "START",
          marginBelow: "NONE"
        )
      }
    )


    13 replies

    konduruc733182
    April 19, 2024

    Hello [mention:3670269dff3147e3822f8c49c86782af:e9ed411860ed4f2ba0265705b8793d05] 

    Why do you want to have a different local variable to store the value? If the user doesn't make any change it would not make any change and if the user makes any change it would simply save the new value.
    May be you can use exact() and have a local which has the older value/pre-loaded value which would not refresh to find if there is any change in the value and disable the submit button if that is what you are trying to do.

    hema.mathivathanan
    April 19, 2024

    Hi Chaitanya, 

    My requirement is when the user upload a document, I need to get the document name from that and populate in the text field which is the "Document name". And that's why I have a separate local variable for the document name. 

    shubhama926776
    Brainy
    April 19, 2024

    Hi [mention:3670269dff3147e3822f8c49c86782af:e9ed411860ed4f2ba0265705b8793d05] 
    Can you try this?

    a!textField(
      label: "File Name",
      labelPosition: "ABOVE",
      value: if(a!isNullOrEmpty(local!docName), local!prepopulatedName, local!docName),  
      saveInto: local!docName,
      refreshAfter: "KEYPRESS"
    ),

    शुभम्
    hema.mathivathanan
    April 19, 2024

    Hi Shubham, 

    tried the above code. The problem with the above code is if the user doesn't change the prepoulated name, then it's not saving the pre populated value to the local variable since there is no user intervention to the text field. 

    harshk1671
    April 19, 2024

    Try using following code:

    a!localVariables(
      local!documentId,
      a!columnsLayout(
        columns: {
          a!columnLayout(
            contents: {
              a!fileUploadField(
                target: cons!APP_FOLDER_TEMPORARY_FOLDER,
                maxSelections: 1,
                value: local!documentId,
                saveInto: {
                  local!documentId,
                  a!save(
                    ri!documentName,
                    index(
                      index(
                        index(
                          a!fileUploadField(value: local!documentId),
                          "contents",
                          null
                        ),
                        "value",
                        null
                      ),
                      "fileName",
                      null
                    )
                  )
                }
              )
            }
          ),
          a!columnLayout(
            contents: {
              a!textField(
                label: "File Name",
                labelPosition: "ABOVE",
                value: ri!documentName,
                saveInto: ri!documentName
              )
            }
          )
        }
      )
    )

    Save the document name in rule input instead of local so you do not need to make any changes on 'SUBMIT' button.
    Output of above code:

    hema.mathivathanan
    April 22, 2024


    Thanks for your reply. I used similar to your code. In the fileUploadFieldd saveinto, saved the uploaded document name to the local variable and it's working fine. 

    johibd1593
    April 22, 2024

    Hi [mention:3670269dff3147e3822f8c49c86782af:e9ed411860ed4f2ba0265705b8793d05] 

    a!localVariables(
    local!docName,
    {
    a!fileUploadField(
    label: "Document",
    target: cons!NA_Upload_Documnet_CONS,
    maxSelections: 1,
    value: ri!document,
    saveInto: {
    a!save(ri!document, save!value),
    a!submitUploadedFiles()
    }
    ),
    a!textField(
    label: "Document Name",
    value: if(
    a!isNullOrEmpty(ri!document),
    null,
    document(documentId: ri!document, property: "name")
    ),
    saveInto: { a!save(local!docName, save!value) }
    )
    }
    )

    You Can Try This Code .

    hema.mathivathanan
    April 22, 2024

    Thanks for your help. With this code, when we enter a new value in the document name it's not reflected. I used like below:
    a!fileUploadField(
    label: "Document",
    labelPosition: "ABOVE",
    target: cons!TEST_APPLICATION_DOCUMENT,
    maxSelections: 1,
    value: local!document,
    saveInto: {
    local!document,
    a!submitUploadedFiles(
    onSuccess: {
    a!save(local!sucess, true),
    a!save(
    local!documentName,
    document(index(local!document, 1), "name")
    )
    },
    onError: a!save(local!sucess, false)
    )
    },
    required: true,
    validations: {}
    )

    a!textField(
    label: "Document Name",
    labelPosition: "ABOVE",
    value: local!documentName,
    saveInto: local!documentName,
    showWhen: a!isNotNullOrEmpty(local!document),
    required: true
    )