prevent user entering text or symbol in a!textdield

Hi,

I am displaying a decimal value in   a!textField as part of an editable grid . 

I would like to put some validation if the user enters a text in this field it should throw error or blank out . 

 

 a!textField(
            value: if(todecimal(ri!items[ri!index].currentMonDis)=0,"",dollar(ri!items[ri!index].currentMonDis)),
          saveInto:{
              ri!items[ri!index].currentMonDis,
             a!save(ri!itemstoken,append(ri!itemstoken,save!value)),
              a!save(ri!items[ri!index].changeOrdiff,todecimal(ri!items[ri!index].currentMonDis)-todecimal(ri!items[ri!index].lastMonDis)),
               a!save(ri!itemstoken,append(ri!itemstoken,todecimal(ri!items[ri!index].currentMonDis)-todecimal(ri!items[ri!index].lastMonDis)))
            }
           
          ),

 

at present , if we enter any text it throws the error message below 

 

Error Evaluating UI Expression
Expression evaluation error in rule 'eds_showitemroweach' (called by rule 'eds_initiaterbepaymentreview') at function a!applyComponents [line 188]: A null parameter has been passed as parameter 1.

 

Can you provide any ideas to prevent user entering text or symbols in this field ?

 

  Discussion posts and replies are publicly visible

Parents
  • One thing you can simply do is the following :

    using the validations and the refreshAfter, for example like this here you can get all kind of validations you want. 

    a!textField(
        label: "first name " & fv!index,
        value: fv!item.firstName,
        saveInto: fv!item.firstName,
        required: true,
        refreshAfter:"KEYPRESS",
        validations:{
          if (len(fv!item.firstName) < 3, "Please enter more",null)
        }
      ),

    I  like using the regex to do Complex Validations . Please find an example how to implement the validation, I personally don't like the option to blank the field to the user if it is not correct, because it can be just 1 characters from a long value, 

    =load(
      local!regexDecimal:"^[\$]?[\u0020]?[+-]?([0-9]*[.])?[0-9]+$",
    
       local!testrows: {
          { data1: "11.0", data2: "$ 1.0" , data3: "$ 1.0"},
          { data1: "11.0", data2: "$ 1.0" , data3: "$ 1.0"},
          { data1: "1.a", data2: "$ 1.a" , data3: "$ 1.a"},
      },
      a!formLayout(
        label: "SAIL Example: Add,Update, or Remove Employee Data",
        contents: {
          a!gridLayout(
            totalCount: count(local!testrows),
            headerCells: {
              a!gridLayoutHeaderCell(label: "Validate1" ),
              a!gridLayoutHeaderCell(label: "Validate2" ),
              a!gridLayoutHeaderCell(label: "Validate3")
            },
            columnConfigs: {
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 )
            },
    
            rows: a!forEach(
              items: local!testrows,
              expression: a!gridRowLayout(
                contents: {
                  a!textField(
                    label: "validate1 " & fv!index,
                    value: fv!item.data1,
                    saveInto: fv!item.data1,
                    required: true,
                    refreshAfter:"KEYPRESS",
                    validations:{
                      if (len(fv!item.data1) < 4, "Please enter more than 4 characters ",null)
                    }
                  ),
                  a!textField(
                    label: "validate2 " & fv!index,
                    value:  fv!item.data2,
                    saveInto: fv!item.data2,
                    required:true,
                    refreshAfter:"KEYPRESS",
                    validations:{
                     
                      if (regexmatch(local!regexDecimal,fv!item.data2),null,"Please enter valid decimal value with/without $ ")
                    }
                  ),
    
                  a!textField(
                    label: "validate3 " & fv!index,
                    value:  if (regexmatch(local!regexDecimal,fv!item.data3),fv!item.data3,null),
                    saveInto: fv!item.data3,
                    required:true,
                    refreshAfter:"KEYPRESS",
                    validations:{
                      if (regexmatch(local!regexDecimal,fv!item.data3),null,"Please enter valid decimal value with/without $")
                    }
                  )
                },
                id: fv!index
              )
            )
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: a!buttonWidgetSubmit(
            label: "Submit"
          )
        )
      )
    )

     

    Hope this helps

    Note: The regex ins a plugin you can find in the shared components. 

     

     

     

Reply
  • One thing you can simply do is the following :

    using the validations and the refreshAfter, for example like this here you can get all kind of validations you want. 

    a!textField(
        label: "first name " & fv!index,
        value: fv!item.firstName,
        saveInto: fv!item.firstName,
        required: true,
        refreshAfter:"KEYPRESS",
        validations:{
          if (len(fv!item.firstName) < 3, "Please enter more",null)
        }
      ),

    I  like using the regex to do Complex Validations . Please find an example how to implement the validation, I personally don't like the option to blank the field to the user if it is not correct, because it can be just 1 characters from a long value, 

    =load(
      local!regexDecimal:"^[\$]?[\u0020]?[+-]?([0-9]*[.])?[0-9]+$",
    
       local!testrows: {
          { data1: "11.0", data2: "$ 1.0" , data3: "$ 1.0"},
          { data1: "11.0", data2: "$ 1.0" , data3: "$ 1.0"},
          { data1: "1.a", data2: "$ 1.a" , data3: "$ 1.a"},
      },
      a!formLayout(
        label: "SAIL Example: Add,Update, or Remove Employee Data",
        contents: {
          a!gridLayout(
            totalCount: count(local!testrows),
            headerCells: {
              a!gridLayoutHeaderCell(label: "Validate1" ),
              a!gridLayoutHeaderCell(label: "Validate2" ),
              a!gridLayoutHeaderCell(label: "Validate3")
            },
            columnConfigs: {
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 )
            },
    
            rows: a!forEach(
              items: local!testrows,
              expression: a!gridRowLayout(
                contents: {
                  a!textField(
                    label: "validate1 " & fv!index,
                    value: fv!item.data1,
                    saveInto: fv!item.data1,
                    required: true,
                    refreshAfter:"KEYPRESS",
                    validations:{
                      if (len(fv!item.data1) < 4, "Please enter more than 4 characters ",null)
                    }
                  ),
                  a!textField(
                    label: "validate2 " & fv!index,
                    value:  fv!item.data2,
                    saveInto: fv!item.data2,
                    required:true,
                    refreshAfter:"KEYPRESS",
                    validations:{
                     
                      if (regexmatch(local!regexDecimal,fv!item.data2),null,"Please enter valid decimal value with/without $ ")
                    }
                  ),
    
                  a!textField(
                    label: "validate3 " & fv!index,
                    value:  if (regexmatch(local!regexDecimal,fv!item.data3),fv!item.data3,null),
                    saveInto: fv!item.data3,
                    required:true,
                    refreshAfter:"KEYPRESS",
                    validations:{
                      if (regexmatch(local!regexDecimal,fv!item.data3),null,"Please enter valid decimal value with/without $")
                    }
                  )
                },
                id: fv!index
              )
            )
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: a!buttonWidgetSubmit(
            label: "Submit"
          )
        )
      )
    )

     

    Hope this helps

    Note: The regex ins a plugin you can find in the shared components. 

     

     

     

Children