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

Kendo MVVM, Validation on window

5 Answers 370 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
sai
Top achievements
Rank 1
sai asked on 08 Aug 2013, 03:55 PM
Hi,

I m currently using kendo MVVM framework and I want to use the validation feature provided by kendo.

I'm facing problem with validation when am displaying controls on a kendo window. here is the link to jsfiddle sample -  http://jsfiddle.net/saisworld/UquQ6/6/


It works for the item row in the table and for other rows it doesn't. Even after clicking the button Validate it doesn't show the validation message.

Please advise.

Thanks
Sai

5 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Valchev
Telerik team
answered on 12 Aug 2013, 11:16 AM
Hi Sai,

The problem occurs because inputs does not have a name attribute. To avoid it, please make sure that each input has a unique name. For example, you can use the record's ID :
<script id="tbl-Sales-editTemplate" type="text/x-kendo-template">
    <tr>
        <td data-bind="text:ID"></td>
        <td><input type="text" name="input#:ID#" data-bind="value:CompanyName, attr: {validationMessage: CompanyNameValidationMsg}" required /> </td>
        <td data-bind="text:LengthOfContract"></td>
        <td data-bind="text:Status"></td>
    </tr>   
</script>

For your convenience I updated the jsFiddle sample:

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
sai
Top achievements
Rank 1
answered on 12 Aug 2013, 01:15 PM
Thanks Alexander. that worked.

I have one more query on the similar topic. Even though the validation message is displayed correctly for all the fields, the underlying view Model is getting updated as soon as we delete text from the text box.  Is there a way to force it to check for validity before updating the underlying  viewmodel?

Thanks
Sai
0
Accepted
Alexander Valchev
Telerik team
answered on 14 Aug 2013, 07:40 AM
Hello Sai,

You may use the set event of the observable object:
For your convenience I updated the jsFiddle sample:
Relevant code is:
salesVM.bind("set", function(e) {
    if(!this.parent().parent().Isvalid()) { //check validity
        e.preventDefault(); //cancel viewmodel update
    }
});


Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
sai
Top achievements
Rank 1
answered on 15 Aug 2013, 10:12 AM
This is completely stopping from updating the underlying viewModel even though validation condition passes.

I have update the JsFiddle - http://jsfiddle.net/saisworld/UquQ6/11/
0
Alexander Valchev
Telerik team
answered on 19 Aug 2013, 08:12 AM
Hello Sai,

The if condition that I used to check the validity seems to be wrong for which I apologize. Please try the following:
salesVM.bind("set", function (e) {
    if (!e.value) {
        e.preventDefault();
    }
});

For your convenience I updated the jsFiddle sample:

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
MVVM
Asked by
sai
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
sai
Top achievements
Rank 1
Share this question
or