Client Side Validation for Particular Web Block

Client Side Validation for Particular Web Block

  

Hi,

I have a Web block in my screen,

In that Web block, I have an screen action. In that action i have enabled client and server validation.

Screen also has some input fields,

When i click screen action inside the web block is it possible to do client side validation for input fields inside that web block (I knew we can do with server side) instead of all the input fields in the screen.

In the below image

when i click "Add Record" link, Is it possible to do client side validation for input fields only in that web block








Hello Sekar,

Yes, you can. At least, if you use a FORM inside the web block, and set the method of the link to AJAX SUBMIT and the validation method to Client & Server, it will validate only the fields in the web block.

Cheers,
Eduardo Jauch

EDIT

But the Link/button need to be INSIDE the form in the web block, or it will validate the Form in the page instead of the form in the web block.

Hello Sekar,

Ofcourse, you can do it. Sekar go with Eduardo approach and I think you can easily resolve this issue by that approach.

Regards

Rajat Agrawal

Hi Jauch,

I am not able to add form tag since i have used nested structure to create my design.

Could you provide an suggestion how to do in my case?


Thanks,

 

Hi Jauch,

I tried to add an "<form>" tag in an expression, with escape content as "No". But its not rendering.


Hello Sekar, 

The short answer for you is: Yes, you can use forms here. See, the forms doesn't require that your controls are connected to the form's "Record", and you can always pass to a form the "nested" structure, if it is a record. And for sure you can use local variables of type structure with the fields you need. So, this is not the problem. The problem is that YOU NEED to use forms, or the client validation will not work the way you want.

Just a question.

How the "Add Record" works?
Are you using the "last" item of the list as an empty line to add new records, so the user just type in it and click the link and your logic persists this information and add's a new item to the list to be the new empty line?

If this is the case (and I think it is), than to make client validation I think you need to change "a little" your structure. Your structure seems to be something like this:

webblock1
       |_List
              |_webblock2 (per line)
                          |_List
                                 |_Fields + webblock3 (per line)

And in webblock3 you have a new list. to the variable column, or they are based on conditions (doesn't matter). Here, you will have to change your structure in order to put the forms in the right place.

But you will need to create a new webblock_X that you will use in the lines of the list of the webblock2, instead of putting things there directly.

The structure of webblock2 will be like this:

webblock2
       |_List
              |_webblock_X (per line)
                        |_FORM
                                 |_Fields + webblock3
                                 |_Add record link

The link should appear only in the last line. No problem, use the CurrentRowNumber and the List.Lenght to know if you must show or hide the link.

Now, it will work.
If you press the linkwith Client&Server validation, everything inside the FORM in webblock X will be validate, even if they are not connected to the form itself, because this connection doesn't matter to validation. The only think matter is that the inputs are inside the form that contains the link with the validation.

You don't have even to use the form. You can keep storing the values in the structures as you are doing now.

This is because the "form" in OutSystems is not an HTML form. It is just a DIV with JavaScript associate to it. Every screen in OutSystems is inside an HTML form. 

But I must say that probably are better ways to do what you are trying to do... Your structure seems to be too much complicated...

Let me know if you didn't understand something or if you need extra help.

Cheers,

Eduardo Jauch

Sekar wrote:

Hi Jauch,

I tried to add an "<form>" tag in an expression, with escape content as "No". But its not rendering.


No...
You shouldn't use the FORM tag, this NEVER will work properly... Use the OutSystems forms like in my previous answer :)

There you will understand also why you shouldn't use a FORM tag in OutSystems (generally speaking).

Hi Jauch,

I have attached my sample with this, This has the my sample design.

I am not able to add form tag in a list.

Could you help me in adding form with in the list


Sekar wrote:

Hi Jauch,

I have attached my sample with this, This has the my sample design.

I am able to add form tag in a list.

Could you help me in adding form with in the list


Hi Sekar.

Don't use HTML Form tag. You will not be able to make this work.
Use the OutSystems FORM. To make this work, you will have to change your structure as I have told you, or you will not be able to do Client validation.

Cheers,
Eduardo Jauch

Hi Jauch,

I got it, I need to add one more web block like below


Then its working fine.



Yes, like I said ;)

I'll do some tests here, because your questions raised some others in my head, like if it is really necessary the FORM to work as I would expect. Thank you for that :)

If you need more help with this, just ask

Cheers,
Eduardo Jauch

Hi Jauch,

I added the web block in between, But validation working only for the first record.

Could you help me what i have missed in that.

I have attached the sample here.

Hello Sekar, 

I need to understand what you are trying to validate and at which moment.

You want to validate when the user add a new line to the list or at the end when it's time to save all data (to database)?

if you are trying to do the second, than what you need is a single form where all the contend is inside it. In this case, you would have something like this:

Page
    |_WebBlock1 (with the list inside it)

In this case, you don't even need the form, as the validation should be performed even if all the controls are outside a form (that is the same as to say you don't need a form, in this case)

If it is the first, you only need a form at the level in which you want to perform the validation.
So, if you want to perform validation for all lines in Webblock1, you put a form around it. If you want to perform validation on all the lines of webblock2 (for a single line of webblock1), you put a form around webblock2.

As you can't put a form directly inside a list (and vice-versa), if this is the case you always need to add a webblock layer to allow this.

Cheers,
Eduardo Jauch

As a side note, if you put a Button/Link INSIDE a form, only THAT form controls will be validate. If it has nested forms, they won't be validate.

Cheers,
Eduardo Jauch

Hi Jauch,










Sekar wrote:

Hi Jauch,










So, you have many lines there.
You need a FORM around those fields AND the Add Record button. This way, only the fields inside this form (that will be around the orange box) will be validate.

But the link Add Records MUST be inside that same form.

Cheers,
Eduardo Jauch

Solution

Hi Jauch,

Thanks for reply, But its making too complex. for me :)

Let me add server side validation on Add Record Link. I hope it will solve my problem.

Thanks a lot for the quick replies.




Solution

Hello Sekar,

I think it is a wise decision.
Even more because client side validation will prevent the action to be calling only if there are missing values that are mandatory or wrong data type. Probably it is not a big deal to validate server side.

Cheers,
Eduardo Jauch