Validation in List Records

Validation in List Records

  

Hi,

I have a List Records of Input Widgets. Based on what the user selects, more or less input fields are generated together with a Label. 


I want to do some custom validation on these input widgets and set a corresponding validation message. 

If I just set the Input Widget to mandatory, everything works just fine. However, I need some custom validation on these Input Widgets... 

When I set the Valid property or the ValidationMessage property for each input widget in my List Records, nothing is shown. If I debug, then the Valid and ValidationMessage give me an -unavailable in current context- message. Any ideas how to do this?  

I'm using OS11 but on OS10 I had the same issue. 

Hi Wietse,


If you iterate the list structure, which holds the record list values, you can validate their content only. See that in this other post there is a reference to this also: https://www.outsystems.com/forums/discussion/5805/validation-inputs-inside-table-records/


You could also choose using webbocks (depending on your use case), and implement the appropriate validation logic on each input change.


Regards,


Solution

Hi Wietse


You can show the messages through JavaScript.

Iterate your ListRecord/TableRecords and when an error occur use the action RunJavascript to show a message.


Here the functions that I use:

/** 
* 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();
}


In the "selector" parameter pass a jQuery selector, like "input[inputName=inputName0]" and add "inputName" to the extended attributs of the input with the value of "inputName" + CurrentRowNumber


Cheers

Solution

Thank you Marco & Victor. Both solution work and are what I was looking for. I've implemented the solution of Victor and thus accepted this as the solution.

Again, thank you both for the help.