简体   繁体   English

如何仅将日期作为角度的引导日期选择器的输入字段值

[英]How to accept only date as input field value for bootstrap datepicker in angular

html 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 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 ie string, numbers etc. How can i limit so it only takes date as input 我有一个bootstrap datepicker元素,我试图只接受日期作为输入,但是它接受各种输入,即字符串,数字等。我如何限制所以它仅将日期作为输入

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}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM