This is a migrated thread and some comments may be shown as answers.

Message on wrong input

2 Answers 311 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Iron
Alex asked on 15 Jan 2016, 04:19 PM

Hi

I need quite a complex validation mechanism as various inputs are related to each other.
I never had problems so far but in my newest application I struggle with the combination of two custom validation rules.

Each rule is applied to an autocomplete input and validation is fired on blur and on various change events. Now, the problem is, that both validation messages are shown on the same input element and not separately for each of them.
Here is my validator setup:

classifiedTaxaValidator = $("#classified_taxa_form").kendoValidator({
            validateOnBlur: true,
            messages: {
                required: "Dieses Feld ist obligatorisch",
                subordination: "Diese Unterordnung ist nicht möglich",
                correctrank: "Der Name passt nicht zur gewählten Rangstufe"
            },
            rules: {
                correctrank: function (input) {
                    if (input.is("[id=taxon_names_autocomplete]")) {
                        console.log('validating name');
 
                        // binomial name chosen ?
                        var nam = input.val();
                        var parts = nam.split(" ");
                        var rank_id = $('#taxon_rank_id').val();
 
                        // exactly uninomial
                        if (parts.length === 1) {
                            return rank_id > 5;
                        }
 
                        // at least binomial name
                        if (parts.length > 1) {
                            return rank_id < 6;
                        }
                    }
                    return true;
                },
                subordination: function (input) {
                    if (input.is("[id=parent_taxa_autocomplete]")) {
                        console.log('validating parent taxon');
                        // rank of current taxon must be lower than rank of parent
                        var taxonRankId = $('#taxon_rank_id').val();
                        return taxonRankId < parentTaxonRankId;
                    }
                    return true;
                }
            }
        }).data("kendoValidator");

Any idea what I am missing here?

Kind regards

Alex

2 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 19 Jan 2016, 04:04 PM
Hello Alex,

Please ensure that you have set name attributes to all validated elements.

http://docs.telerik.com/kendo-ui/controls/editors/validator/overview#definition-of-custom-error-messages

In addition, you may need to customize the validator messages' position, otherwise they will appear inside the AutoComplete widgets' markup and break their layout.

http://docs.telerik.com/kendo-ui/controls/editors/validator/overview#customization-of-tooltip-position

Regards,
Dimo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Alex
Top achievements
Rank 1
Iron
answered on 20 Jan 2016, 08:34 AM

Hi Dimo

thank you very much for your answer - and sorry - I missed the mandatory name attribute. I use the Autocomplete just to select a value but don't want to send that value with the form. (Instead I send the id of the selected item). Therefore I didn't set a name attribute.

Kind regards

Alex

Tags
Validation
Asked by
Alex
Top achievements
Rank 1
Iron
Answers by
Dimo
Telerik team
Alex
Top achievements
Rank 1
Iron
Share this question
or