Skip to main content
Inspiring
Mar 7, 2023 1:19 AM UTC
Question

Dynamically add mobile number

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

Participating Frequently
Mar 7, 2023 4:08 AM UTC

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))
            )
          }
        )
      )
    }
  )
)

Inspiring
Mar 7, 2023 4:13 AM UTC

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

Participating Frequently
Mar 7, 2023 4:21 AM UTC

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
Brainy
Mar 7, 2023 3:31 PM UTC

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