148
Views
5
Comments
Solved
Set form field invalid message during onRender

Hi, 


I have a form component inside a block and when the block is created I want to set all of the inputs to invalid and add a custom validation message to them. I have tried to assign them on a couple of the lifecycle hooks (OnReady, OnRender) and debugging through it, it looks like these are being set correctly, but the input fields do not appear on the screen as invalid and the validation message is not there. Is there a way to instantiate a form and set the validity of the input fields/messages? 


For further context I have the form in a block as on one of my screens a user can create multiple forms, one for each business item. There is one save button on this page which will submit all of the form data from all of the blocks that have been created. This button I have set the Built-in Validations property to False, as I do not want it to replace my custom validation messages with the default field is mandatory text. 

Thanks

2024-12-10 04-40-04
Gitansh Anand
Solution

Hi John Ronis, I observed what you mentioned, it seems that OutSystems does not show the error message even if the input is set invalid if the value of the input is empty when it is displayed. I have found a workaround for this. First, inside the OnReady I assign a dummy value to the input (I prefer the prompt value) and set the input invalid. Then, I have used a JS in the OnReady to call another action with a timeout of 100ms to reset the value of the input to what it should be. I'm including the OML with the same implementation.

Thanks
Gitansh Anand

Test.oml
2024-12-10 04-40-04
Gitansh Anand

Hi John Ronis, It works for me in the OnReady event of the block. I am adding an OML; please look if there is any difference in your logic, like perhaps you removed the default "form-control" class from the input by mistake.

Thanks
Gitansh Anand 

Test.oml
UserImage.jpg
John Ronis

Hi Gitansh, 
Thanks for the speedy reply. 

I do have the "form-control" class on the inputs.

And I did try again with the OnReady as you have in the attached oml and was able to get some of the fields to show the validation message (the last 3). I have an example in the screenshot below where on page load it had 5 existing records for which the last 3 have the validation message showing. However, when I click the Add IP Range button, which in my screen will add another of the same block below the existing ones, the validation message is not shown. 

Is there some reason that it would only work on the last few, some other process is still needs to finish before the OnReady fires?


2024-12-10 04-40-04
Gitansh Anand
Solution

Hi John Ronis, I observed what you mentioned, it seems that OutSystems does not show the error message even if the input is set invalid if the value of the input is empty when it is displayed. I have found a workaround for this. First, inside the OnReady I assign a dummy value to the input (I prefer the prompt value) and set the input invalid. Then, I have used a JS in the OnReady to call another action with a timeout of 100ms to reset the value of the input to what it should be. I'm including the OML with the same implementation.

Thanks
Gitansh Anand

Test.oml
UserImage.jpg
John Ronis

Hi Gitansh, 

This worked! Thanks for looking into it and coming back with quick, concise answers!

Thanks

2023-04-16 15-25-31
Krishnanand Pathak

Hi John,

Please check the demo here

Sharing the oml in which there is a screen and a block inside the screen.
At on ready we are settting up form field invalid.

Regards
Krishnanand Pathak

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