Skip to main content
March 7, 2023
Question

Dynamically add mobile number

  • March 7, 2023
  • 4 replies
  • 0 views

how should i approach from appian side ... to add mobile number dynamically ..

For now i am having  blank text field where user can enter mobile number.. next to it i want to provide add button .. so whenever it gets clicked a new text field should appear to add new mobile number with validation ... 

a!localVariables(

  local!add ,
  local!npi,
  a!sideBySideLayout(
    items: {
      a!sideBySideItem(
        item: a!textField(
          label: "Mobile Number",
          labelPosition: "ABOVE",
          value: local!npi,
          saveInto: local!npi,
          validations: if(
            a!isNullOrEmpty(local!npi),
            {},
            if(
              not(
                regexmatch("^([0-9]{" & 10 & "})$", local!npi)
              ),
              "Maximum " & 10 & " digits are allowed",
              ""
            )
          )
        )
      ),
      a!sideBySideItem(
        item: a!linkField(
          label: "",
          links: {
            a!dynamicLink(
              label: "add new ",
              value: true(),
              saveInto: local!add 
            )
          }
        )
      )
    },
    
  )
)

4 replies

March 7, 2023

Hii, Klaus34
you can try this

a!localVariables(
  local!npi:{
    {
      mobileNo:""
    }
  },
  a!columnsLayout(
    columns:{
      a!columnLayout(
        contents: a!forEach(
          items: local!npi,
          expression:  a!textField(
            label: "Mobile Number",
            labelPosition: "ABOVE",
            value: fv!item.mobileNo,
            saveInto: fv!item.mobileNo,
            validations: if(
              a!isNullOrEmpty(fv!item.mobileNo),
              {},
              if(
                not(
                  regexmatch("^([0-9]{" & 10 & "})$", fv!item.mobileNo)
                ),
                "Maximum " & 10 & " digits are allowed",
                ""
              )
            )
          )
        )
      ),
      a!columnLayout(
        contents: a!linkField(
          label: "",
          links: {
            a!dynamicLink(
              label: "add new ",
              value: {
                mobileNo:""
              },
              saveInto: a!save(local!npi,append(local!npi,save!value))
            )
          }
        )
      )
    }
  )
)

March 7, 2023

thanks it helped .. can we do by comma separated in one text field only ??

Like this 1234567890, 1234567890 with validation  of 10 digits .. while saving i will iterate by a! for each

March 7, 2023

no, in one text field, you cannot add multiple numbers, but you can do it by using a text field  in side by side layout,

a!localVariables(
  local!npi:{
    {
      mobileNo:""
    }
  },
  a!sideBySideLayout(
    items: {
      a!forEach(
        items: local!npi,
        expression: a!sideBySideItem(
          item: a!textField(
            label: "Mobile Number",
            labelPosition: "ABOVE",
            value: fv!item.mobileNo,
            saveInto: fv!item.mobileNo,
            validations: if(
              a!isNullOrEmpty(fv!item.mobileNo),
              {},
              if(
                not(
                  regexmatch("^([0-9]{" & 10 & "})$", fv!item.mobileNo)
                ),
                "Maximum " & 10 & " digits are allowed",
                ""
              )
            )
          )
        )
      ),
      a!sideBySideItem(
        item: a!linkField(
          label: "",
          links: {
            a!dynamicLink(
              label: "add new ",
              value: {
                mobileNo:""
              },
              saveInto: a!save(local!npi,append(local!npi,save!value))
            )
          }
        )
      )
    }
  )
)

abhayd3663
March 7, 2023

Following page has the details on what you are looking for - 

https://docs.appian.com/suite/help/22.4/recipe-add-multiple-text-components-dynamically.html