Appian field validation erases field value

383 views Asked by At

I have an appian form with fields which should accept only numbers. There is a submit button and a cancel button.

However, i cannot make the buttons restore original values on failed validations.

When a submit button is clicked, if the values are not numbers, error message should appear and the original value should be restored. When the cancel button is clicked, original value should be restored.

This is the validation i am using on that field :

validation: if(typeof(local!myLocalObject.numField1)<>1,
  "This field must have a numeric value",
  null
)

cancel button contains the following code :

saveInto: {
  ...
  a!save(local!myLocalObject.numField1, ri!retrievedFromDB.numField1),
  ...
}

save button contains the following code :

saveInto: {
  ...
  if(typeof(local!myLocalObject.numField1)<>1,
    a!save(local!myLocalObject.numField1, ri!retrievedFromDB.numField1),
    null
  )
  ...
}

So this is what happens :

I have the field with a numeric value, and i make it editable :

I have the field with a numeric value

When i change the value to text and click submit,

enter image description here

It should restore the original value and display the error :

enter image description here

But what happens, is that the field becomes blank, with no value at all, and no error message. It can then be saved to DB as null which is a mistake. enter image description here

(Note, this also happens when i just click out of that field)

The field type is textField and its value and saveinto are both set to local!myLocalObject.numField1

I have tried to use integerField instead, but then when I cancell out of saving, it fails to restore the original value :

enter image description here

and i have to reload the page to make the error message and the incorrect value go away.

1

There are 1 answers

0
Lazaruss On

Here is the solution. When you do it like this :

local!myLocalObject: 'type:...'(
    ...
    numericField1 : ri!ruleInput.numericField1,
    ...
)

textField: {
    label: "Numeric Field 1",
    value: local!myLocalObject.numericField1,
    saveInto: local!myLocalObject.numericField1
    ...
}

myLocalObject.numericField1 is predefined to have a numeric value because myLocalObject is of the same type as the rule input. So the text field will parse automatically anything you type there.

This is the workaround i am using :

local!myNumericField1 : ri!ruleInput.numericField1,


textField: {
    label: "Numeric Field 1",
    value: local!myNumericField1,
    saveInto: local!myNumericField1
    ...
}