Hello everyone,
Here is the code for a field. When the user gives an input, there are some controls that should be verified. I want to add some code so that if the user gives an input that doesn't satisfy the condition, the field should be initialized as empty. How can I do this, please?
a!integerField( label: "Montant Apport", labelPosition: "ABOVE", placeholder: "Donner le montant exact de l'apport", value: ri!record['recordType!{3e104763-60d6-49a4-8cdb-405e073de678}PBY prêt.fields.{0f648b9f-079f-483f-87ad-d8a64c53802e}montantApport'], saveInto: ri!record['recordType!{3e104763-60d6-49a4-8cdb-405e073de678}PBY prêt.fields.{0f648b9f-079f-483f-87ad-d8a64c53802e}montantApport'], required: true(), validations: { if( and( not(isnull(ri!record['recordType!{3e104763-60d6-49a4-8cdb-405e073de678}PBY prêt.fields.{0f648b9f-079f-483f-87ad-d8a64c53802e}montantApport'])), not(isnull(ri!record['recordType!{3e104763-60d6-49a4-8cdb-405e073de678}PBY prêt.fields.{5c6f5fa8-85d3-4b23-af45-80a1b6b0c364}montantPret'])) ), if( ri!record['recordType!{3e104763-60d6-49a4-8cdb-405e073de678}PBY prêt.fields.{0f648b9f-079f-483f-87ad-d8a64c53802e}montantApport'] < (0.2 * ri!record['recordType!{3e104763-60d6-49a4-8cdb-405e073de678}PBY prêt.fields.{5c6f5fa8-85d3-4b23-af45-80a1b6b0c364}montantPret']), "Le montant de l'apport doit être au moins égal à 20% du montant demandé pour le prêt.", null ), null ) } ),
Discussion posts and replies are publicly visible
a!save() is your friend.
You didn't really specify what condition you were imagining, so I'll go ahead and offer a straightforward example:
a!localVariables( local!myInteger: null(), a!integerField( label: "Positive Integer Only", value: local!myInteger, saveInto: { a!save( local!myInteger, if(save!value < 0, null(), save!value) ) } ) )
This will, of course, check the user input and, if it fails the condition (being greater than zero), it saves NULL into the local variable, and otherwise, saves the entered value. The condition here is arbitrary - you can make the condition anything that you can write as the boolean condition of an if() statement.
should i give the if condition in the saveInto instead of the validation ?
if( and( not(isnull(ri!record['recordType!{3e104763-60d6-49a4-8cdb-405e073de678}PBY prêt.fields.{0f648b9f-079f-483f-87ad-d8a64c53802e}montantApport'])), not(isnull(ri!record['recordType!{3e104763-60d6-49a4-8cdb-405e073de678}PBY prêt.fields.{5c6f5fa8-85d3-4b23-af45-80a1b6b0c364}montantPret'])) ), if( ri!record['recordType!{3e104763-60d6-49a4-8cdb-405e073de678}PBY prêt.fields.{0f648b9f-079f-483f-87ad-d8a64c53802e}montantApport'] < (0.2 * ri!record['recordType!{3e104763-60d6-49a4-8cdb-405e073de678}PBY prêt.fields.{5c6f5fa8-85d3-4b23-af45-80a1b6b0c364}montantPret']), "Le montant de l'apport doit être au moins égal à 20% du montant demandé pour le prêt.", null ), null )
hrshkar said:should i give the if condition in the saveInto instead of the validation ?
They are mutually exclusive. You can do either, but you need to pick one.