20
Views
1
Comments
Solved
Reactive Web - Custom validation within a list group

Hello,

I have a question about creating custom validations on input fields in a list form. I did review the past post about it but I have a few question... please see below:


The link:

https://www.outsystems.com/forums/discussion/42182/validation-in-list-records/


=========================================================================================

The solution:

/** 

* Add a custom message

**/

function addMessageToInput(selector, message) {

    $(selector).addClass('Not_Valid');

    $(selector).after('<span class="ValidationMessage">' + message + '</span>');

}


/** 

* Clear messages

**/

function clearMessage(selector) {

    $(selector).removeClass('Not_Valid');

    $(selector).next('span.ValidationMessage').remove();


}

===========================================================================================

Okay my question is this, how would I be able to grab the input id dynamically of the input field? I understand that unlike a form, a list does not have a generated ID hence the reason that we are unable to exploit the auto validation functionally in the platform as we can with a form. I could actually just create a form and add the inputs fields there but I would like to learn how to perform this logic  since I am pretty much finished with my use case with the exception of a couple of needed custom  input validations. 

I see that I am able to get the id of the entire list itself, should I implement some process to copy the input's individual id to this id or is there another way around? Perhaps the list id is a it is, a list and I should use the list element [0-length] to obtain it from the fields  but how would I do that. Would anyone mind breaking this solution down a little further?


Thanks,

Otis

Rank: #171
Solution

Hi Otis, 

When using a List with input, the platform generates an ID at runtime for each input.

Indeed you cant access the ID directly because it is not part of the list, so you can't use something like the current.inputId for each line.

An idea of what you can do, is create web blocks for a custom input.

For example, imagine that you have a web block that receive a text, inside this web block you can access the ID of each input in their own scope, and define your custom logic for it. 

In this case I imagine you will not able to click a button and define a custom message for each input, because the functions would need to be inside the web block scope.


If you need to apply the classes and messages at a button click, you can use a generic selector to get all inputs inside your list, something like $(.list input) and then iterates this list to validate the value selected. and apply or not apply your validations for each input element.


Cheers and Regards,

RR :)