1

its a simple form a drop down and a save button. On page load Select should be ng-invalid because it is required and nothing is selected but form and select both are ng-valid and save function is called. and once i select any thing and un select it. then it behaves properly.

            <form role="form" name="frmVariableConfig" id="frmVariableConfig" novalidate ng-submit="frmVariableConfig.$valid && saveChanges()">

            <div>
                <div class="form-group">
                    <div class="form-group control-group">
                        <span>Logic</span>


                        <select name="service_id" class="Sitedropdown" style="width: 220px;"
                                ng-model="CurrCustomer.Logic"
                                ng-options="service.ServiceID as service.ServiceName for service in services"
                                required="">
                            <option value="">Select Service</option>
                        </select>
                    </div>

                </div>
            </div>
            <div>
                <button type="submit" class="btn btn-sm text-right">Save</button>
            </div>
        </form>

where the controller code looks like this.

(function () {
'use strict';
var controllerId = 'dashboard';
angular.module('app').controller(controllerId, ['$scope', dashboard]);

function dashboard($scope) {


    $scope.CurrCustomer = {};
    $scope.CurrCustomer.Logic = false;
    $scope.saveChanges = function () {
        alert('function called');

    };
    $scope.services = [
{ ServiceID: 1, ServiceName: 'Service1' },
{ ServiceID: 2, ServiceName: 'Service2' },
{ ServiceID: 3, ServiceName: 'Service3' }
    ];
}})();

1 Answer 1

1

You need to remove the setter $scope.CurrCustomer.Logic = false; from your controller that is filling that ng-model and making it valid on controller load. After filling that CurrCustomer.Logic value it become valid input as it is required.

Sign up to request clarification or add additional context in comments.

7 Comments

it helped. but now the problem is that i cant see validation message "this is the required field"
rest is fine that it wont allow me to call save function unless something is selected. but i cant see validation message. does it have somethign to do with novalidate ?
@RaasMasood where is that message I don't see in your markup? Are you talking about browser popup?
i am talking about that unobtrusive validation error that pops up if something is wrong with the validation .
@RaasMasood yes..that is because novalidate attribute
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.