4

I have validation issue if i use k-ng-model on field that field is not required with Angularjs validation , User can submit the form so below code field is required even i dont select the value user can still submit the form.. Any idea how to solve it ?

main.html

<div class="row">
   <div class="form-group col-md-12">
     <label for="themesList" class="required col-md-4">Themes:</label>
        <div class="col-md-8">
         <select class="multiselect" kendo-multi-select="themes"
                                k-options="challengThemesOptions" data-text-field="'text'"
                                data-value-field="'id'" name="themesList"
                                k-ng-model="challengesDTO.themesKyList" required
                                id="themesList"></select>
          <p class="text-danger" ng-show="addChallengeForm.themesList.$touched && ddChallengeForm.themesList.$error.required">Theme(s) is required</p>
        </div>
    </div>
  </div>
Garry
  • 4,996
  • 5
  • 32
  • 44
aftab
  • 535
  • 4
  • 13
  • 46

2 Answers2

4

You can use ng-model with k-ng-model, Try assigning ng-model to a seperate variable and use ng-required.

<select class="multiselect" kendo-multi-select="themes"
                            k-options="challengThemesOptions" data-text-field="'text'"
                            data-value-field="'id'" name="themesList"
                            k-ng-model="challengesDTO.themesKyList" ng-model="challengesDTO.themesKyListValue" ng-required
                            id="themesList"></select>
JEROM JOY
  • 4,300
  • 3
  • 13
  • 14
  • When I used the same `ng-model` as `k-ng-model`, it updated the model, but the dropdown did not display the value. I found I could use the same object as set in the `data-value-field` with no problems. So for this example, it would be `ng-model="challengesDTO.themesKyList.id"`. – HaveSpacesuit May 16 '18 at 19:12
3

This solution worked for me: kendo ui, angular require validation for numeric text box

Just create a hidden input for the each kendo widget and bind the model from your k-ng-model also to the ng-model of the hidden field. The k-ng-model seems to be no NgModelController, which is why the validators cannot hook into the models $validators and do their work.

<input kendo-date-time-picker k-ng-model="$ctrl.event.endDate"></input>
<input type="hidden" name="endDate" ng-model="$ctrl.event.endDate" required></input>
Community
  • 1
  • 1
Jensen
  • 1,229
  • 12
  • 27