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

  • 0
    Certified Lead Developer
    in reply to jinsongc

    This is because the data type is float in a floatingPointField(). The float data type stores an approximate value not an exact value. You will have to use a text field and put some manipulation on the save!value.

  • Hi, I tried to use a!floatingPointField(), but some numbers inputted will be cut off, for example: 55.44444444 to 55.44444, 55.55555555 to 55.55556 and 55555555555 to 555555600000. How do you fix this? I am using Appian version of 17.4.
  • You can and should still use the text field so that you have the option of the dollar() function. When saving the data in the value to your ri!, which I assume is a Decimal type, you need to wrap it in an if(). All other text that isn't decimal returns a null value when you try to use toDecimal() and store it in a Decimal type. This is your isDecimal function already built.

    a!save( ri!yourDecimal, if(APN_isBlank(toDecimal(save!value)), 0.0, toDecimal(save!value) )

    The save above saves a 0.0 instead of null if the toDecimal comes back null. This should render any attempt to type anything else like "Lorem Ipsum" into your decimal into a 0.0. If you don't have access to APN_isBlank, isNull() should also give the same result. No regex needed; sorry regex fans.
  • Just curious, why don’t you ask or install regex plugin? Any policy constraint on plugins installation?
    For me this can be the simpler option.

    I am starting thinking that this might be possible, but a rule with a lot of validations and loops, this can be implemented for sure but in my opinion I am not sure that’s the best choice.

    What about taking out the dollar symbol (put it in the label) and using the @vinay suggestion?

    I will not encourage you to do the rule isDecimal without regex hehe =D. But please let me know your decision. This is a common way to solve this kind of scenarios.

    stackoverflow.com/.../how-to-check-a-string-contains-only-digits-and-decimal-points

    I will leave this link here Just in case
    forum.appian.com/.../summary


    Jose
  • Thanks Josep,

    I am using the first approach as we dont have regex plugin available on our cloud

    validations:{
    if ( isDecimal(myval),"Please enter a valid decimal field " ,{})
    }

    My question is how to write isDecimal ( Text ) . do we have any functions or any ideas to create one ?
  • 0
    Certified Lead Developer

    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. 

     

     

     

  • More over if i use the floatingPointField , I am not getting the dollar symbol
  • 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.

    Thanks i removed the extra save and changed to floating point field . still when i type any text , it is giving this error

  • Hi,

    The actual value is save in ri!items[ri!index], and unnesssary you maintain the extra duplicate variable, which is no use.
  • =a!gridRowLayout(
            Id: ri!index,
    
            contents: {
               a!textField(
                value: if(rule!APN_isBlank(ri!items[ri!index].sacId), "",ri!items[ri!index].Id ),
                 readonly:true()
              ),
              a!textField(
                value: if(rule!APN_isBlank(ri!items[ri!index].sacName), "", ri!items[ri!index].Name),
                 readonly:true()
              ),
               a!textField(
                value:if(rule!APN_isBlank(ri!items[ri!index].sacStatus), "",ri!items[ri!index].Status),
                readonly:true()
              ),
              
              a!textField(
                value: if(isnull(ri!items[ri!index].lastMonDis),"",dollar(todecimal(ri!items[ri!index].lastMonDis))),
                readonly:true()
              ),
               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)))
                }
               
              ),
               a!textField(
                value: if(todecimal(ri!items[ri!index].currentMonDis)=0,"",dollar(todecimal(ri!items[ri!index].currentMonDis)-todecimal(ri!items[ri!index].lastMonDis))),
                saveInto:{
                  ri!items[ri!index].changeOrdiff,
                   a!save(ri!itemstoken,append(ri!itemstoken,save!value))
                },
                 readonly:true()
              ),
               a!textField(
                value: if(isnull(ri!items[ri!index].currentMonHld),"",dollar(ri!items[ri!index].currentMonHld)),
                 readonly:true()
                
              ),
               a!textField(
                value: if(todecimal(ri!items[ri!index].accHldAmount)=0,"",dollar(ri!items[ri!index].accHldAmount)),
                  saveInto:{
                  ri!items[ri!index].accHldAmount,
                 a!save(ri!itemstoken,tostring(append(ri!itemstoken,save!value)))
                }
              ),
               a!textField(
                value: if(rule!APN_isBlank(ri!items[ri!index].reason), "", ri!items[ri!index].reason),
                saveInto:{
                  ri!items[ri!index].reason,
                  a!save(ri!itemstoken,append(ri!itemstoken,save!value))
                }
              ),
         
            })

    Hi, Jamal , Please find the code snippet