I have to validate my form based on lookup field value that change on user inputs.
Everything is ok but i can't validate one field: i'd like to set a validation if the value of my lookup field is empty (meaning that no lookup result is found and that combination of two input field is not valid).
I've tried "", "null" and "undefined" but no results.
my code is
fd.rendered(function() {
fd.field('CodiceCollaborazione').addValidator({
name: 'ValidaIDCombinato',
error: 'La combinazione di indirizzo email e codice collaborazione non è valida! Controllare i dati inseriti.',
validate: function(value) {
if (fd.field('IDCombinato').value == "") {
return false;
}
return true;
}
});
function MatchRisultati() {
fd.field('NomeCollaborazione').value = fd.field('CodiceCollaborazione').value;
fd.field('IDCombinato').value = fd.field('CodiceCollaborazione').value + fd.field('IndirizzoEmail').value;
}
// Calling MatchRisultati when Status value changes
fd.field('CodiceCollaborazione').$on('change',MatchRisultati);
fd.field('IndirizzoEmail').$on('change',MatchRisultati);
// Calling MatchRisultati on form loading
MatchRisultati();
});
fd.field('CodiceCollaborazione').addValidator({
name: 'ValidaIDCombinato',
error: 'La combinazione di indirizzo email e codice collaborazione non è valida! Controllare i dati inseriti.',
validate: function(value) {
if (!fd.field('IDCombinato').value) {
return false;
}
return true;
}
});
1 -First time a open the form, no error present.
2 - Change the value of "CodiceCollaborazione" to a value that returns empty value on the lookup field "IDCombinato"
3- Got an error as expected because the lookup field is empty.
4- Change the value of "codiceCollaborazione" to a value that match the lookup field "IDCombinato"
5- Error still there and that's unexpected 'cause the lookup field now has a value.
The field "Codice Collaborazione" where i'd like to have validation is a masked field.... don't know if this changes something.
No, it contains list of values based on an excel file.
It contains a concatenated string with two values that are also two input fields in the form: when this 2 input fields changes values, if the lookup field has the same concatened string, its value is shown. Otherwise its value i expect is empty.
I'd like to catch this "empty" value and use it as validation exception.
Dear @vigand,
You can check for matches by looping through all the options in the dropdown, like this:
var value = 'Test 3';
var options = fd.field('DropDown1').widget.dataSource.data();
var match = false;
for(var i = 0; i < options.length; i++){
if(value == options[i].text){
match = true;
break;
}
}
console.log(match);