Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

html

                 <form name="eventInformation" id="eventInformation"><label class="required"> Occurence Date </label>
                     <p class="input-group">
                       <input type="text" class="form-control" uib-datepicker-popup="{{format}}" ng-model="formData_EventDetails.eventOccurDate"
                              is-open="popup[0].opened" datepicker-options="dateOptions" close-text="Close" required/>
                    <span class="input-group-btn">
                    <button type="button" class="btn btn-default" ng-click="open(0)"><i class="glyphicon glyphicon-calendar"></i></button>
                    </span>
                    </p>

                <div class="col-sm-2 pull-right">
                          <button class="btn btn-block btn-primary ebtn"
                                  ng-disabled="eventInformation.$invalid"
                                  ng-click="submit()">Save</button>
                      </div>
</form>

javascript

                        $scope.format = 'yyyy/MM/dd';


                        $scope.dateOptions = {
                            formatYear : 'yy',
                            startingDay : 1
                        };

                        $scope.popup = [];
                        for (i = 0; i < 10; i++) {
                            $scope.popup[i] = {
                                opened : false
                            };
                        }

                        $scope.open = function(i) {
                            $scope.popup[i].opened = true;
                        };

I have bootstrap datepicker element which i am trying to only accept date as input, but it accepts all kinds of inputs i.e. string, numbers etc. How can i limit so it only takes date as input

share|improve this question
    
Possible duplicate Bootstrap datepicker and bootstrap validator – Igor Mar 2 '16 at 18:04

Since it's a input text box, You can't restrict the user to enter invalid characters(default behavior).

But you can stop the model update operation, when the user provides wrong date (for that you need to setup following attributes on your input element)

ng-model-options="{allowInvalid: false}"
share|improve this answer
    
another weird thing to notice is that submit button is disabled when i input some string value, which means ng-disabled="eventInformation.$invalid" is true for some reason and is recognizing as date field – ua_boaz Mar 2 '16 at 18:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.