How to check the field is mandatory in client server check?
Question

Hi All,


I want to do the check whether it is mandatory field or not? I already set the field is Mandatory, but i want to do another check at backend. How to do? just avoid the hacker inject.

Please find the attached file.


Thank you


mandatory.png

mvp_badge
MVP
Solution

Hi Jing,

In addition to the suggestion given by Jose, you can also use JS to achieve the same use case.

1) Define a client function in the Logic tab, with an input parameter called ElementId (Text data type) and Output parameter called IsMandatory (Boolean data type)

2) Within the JS node, use the below script to check the declaration of a mandatory property in the element

JS Snippet:

var elem = document.querySelector('#' + $parameters.ElementId);
$parameters.IsMandatory = elem.hasAttribute('required');

3) Call the defined function in the Screen action flow.


I hope this helps you!


Kind regards,

Benjith Sam

You're a JS master :)

Thank you, Your sample is useful.

mvp_badge
MVP

You're welcome, Jing.

Glad to help you :)


Kind regards,

Benjith Sam

Hi Jing,

if you create a local boolean variable and assign it to the Mandatory property of the widget you can have control in backend.

Regards

mvp_badge
MVP
Solution

Hi Jing,

In addition to the suggestion given by Jose, you can also use JS to achieve the same use case.

1) Define a client function in the Logic tab, with an input parameter called ElementId (Text data type) and Output parameter called IsMandatory (Boolean data type)

2) Within the JS node, use the below script to check the declaration of a mandatory property in the element

JS Snippet:

var elem = document.querySelector('#' + $parameters.ElementId);
$parameters.IsMandatory = elem.hasAttribute('required');

3) Call the defined function in the Screen action flow.


I hope this helps you!


Kind regards,

Benjith Sam

You're a JS master :)

Thank you, Your sample is useful.

mvp_badge
MVP

You're welcome, Jing.

Glad to help you :)


Kind regards,

Benjith Sam

Ok,

so I might be misreading this question and seeing things too simplistically, but I thought Jing was talking about having a server side check on top of the client side Mandatory feature of an input field.

For this, I think the answer is just to follow the best practice of never just calling entity actions directly from any UI, but exposing wrapper actions on your CS / backend module and building the necessary checks in there to safeguard the integrity of your data, before saving them into the database.

Of course, for simple rules like mandatory, or referential, you will probably have some of that built into your datamodel as a last defense, but you really don't want your users to be confronted with a database exception, I think.

Dorine

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.