How is your experience with the OutSystems Community?
122
Views
4
Comments
Solved
Input inside of Block inside of Form does not invalidate the Form
Question

I have an Input inside of a Block which is inside of a Form.

When I submit the Form it becomes invalid if the input is blank and mandatory which is great.

However, I have a few custom validation (e.g. the value in the input must be greater than 200) and when I run those custom validations in the submit button logic and then manually set the Input.valid property of those inputs to false if invalid, the Form stays valid.

So when an Input is inside of a Block it seems to change the functionality/consequence of manually setting the inputs validity on the outer Form. I personally did not expect this...

Is this the expected behaviour, and if so - why, and is there a way around this as I would like this automatic form invalidation to stay consistent.

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

Hi @Nicholas Campbell,

I was just trying to reproduce to come up with a workaround, but i'm not really following what exactly you are doing :

  • where is the submit button, and the action connected to it, in the form or in the block
  • where is the validation logic on the input, and does it get executed (ie if button is on form and logic is in block, how does that happen ?)
  • if button is in the same block as the inputs, what is outside the block then, only the form itself ?  why ?

Anyway, regardless of what you are doing, invalidating an input in a block does not trigger the enclosing form to be invalidated, I think that's probably wrong / a bug ??  But maybe it is not considered a very likely usecase and too much work, or something, that's for someone of Outsystems to answer.

Dorine

2022-11-02 07-18-33
Nicholas Campbell

Hi @Dorine Boudry  thanks for validating this for me.

It is a bit of a strange use case yes but quite frustrating that it does not work as expected. It is for a custom reusable component I am building. I am using JS to trigger the invalidation of an Input inside the component - it is just one input in the component, but the component will be inside a Form on my screen amoung other inputs - so I want the invalidtion of the input inside of my component to invalidate the enclosing Form just like doing so for any of the normal inputs would do.

2021-09-06 15-09-53
Dorine Boudry
 
MVP

yes,

it is odd that it doesn't work, but i doubt this is a common enough use case to do something about it.

As a workaround, you could put a dummy display:none input on the parent form, and invalidate that one whenever the one in the block is invalid. I would try to set it up as an invisible input in a placeholder on the block, so wherever you put the block, it is also automatically there.

Dorine

2022-11-02 07-18-33
Nicholas Campbell

Hi Dorine

Thanks for the workaround. Although I agree this would work, it would be very strange for other developers to try use. So I am going to rather just invalidate it manually for now and hopefully OutSystems can fix this issue... not super helpful though.

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