简体   繁体   English

javascript范围日期选择器脚本与html5形式的angular js组合

[英]A javascript range date selector script combined with angular js in form html5

As the title explaines, I have a simple javascript code which allows me to select a date range in input. 如标题所述,我有一个简单的javascript代码,可让我在输入中选择日期范围。

<script type="text/javascript">
    $(document).ready(function () {                
         // create jqxcalendar.
         $("#Datepicker").jqxDateTimeInput({ 
         width: 197, 
         height: 32,  
         selectionMode: 'range' 
});

         $("#Datepicker").on('change', function (event) {
         var selection = $("#Datepicker").jqxDateTimeInput('getRange');
         if (selection.from != null) {
         $("#selection").html("<div>From: " + selection.from.toLocaleDateString() + " <br/>To: " + selection.to.toLocaleDateString() + "</div>");
}
});
         var date1 = new Date();
         var date2 = new Date();
         $("#Datepicker").jqxDateTimeInput('setRange', date1, date2);
});
</script>

Next, I have an AngularJS form which uses ng-model to show me actual values from database in inputs and allows me to modify those values directly. 接下来,我有一个AngularJS表单,该表单使用ng-model向我显示输入中来自数据库的实际值,并允许我直接修改这些值。 The form example can be found HERE and has not any date inputs. 可以在此处找到表单示例,并且没有任何日期输入。

<form class="form-horizontal alert alert-warning" id="editForm" ng-submit="UpdateInfo(currentUser)" hidden>
    <input type="text" class="form-control" ng-model="currentUser.weekOneFirst" value="{{currentUser.weekOneFirst}}">
</form>

And Angular script: 和Angular脚本:

 var crudApp = angular.module('crudApp', []);
 crudApp.controller("DbController", ['$scope', '$http', function($scope,      $http) {
 scope.currentUser = {};
 $scope.UpdateInfo = function(info) {
     $http.post('configuration/program/databaseFiles/updateDetails.php', {
         "id": info.id,
         "name": info.username,
         "email": info.nume_prenume,
         "address": info.parola,
         "gender": info.rol_user,
         "locatie": info.locatie,
         "locatieTwo": info.locatieTwo,
         "locatieThree": info.locatieThree,
         "locatieFour": info.locatieFour,
         "sambata": info.sambata,
         "sambataTwo": info.sambataTwo,
         "sambataThree": info.sambataThree,
         "sambataFour": info.sambataFour,
         "tura": info.tura,
         "turaTwo": info.turaTwo,
         "turaThree": info.turaThree,
         "turaFour": info.turaFour,
         "weekOneFirst": info.weekOneFirst,
         "weekOneLast": info.weekOneLast,
         "weekTwoFirst": info.weekTwoFirst,
         "weekTwoLast": info.weekTwoLast,
         "weekThreeFirst": info.weekThreeFirst,
         "weekThreeLast": info.weekThreeLast,
         "weekFourFirst": info.weekFourFirst,
         "weekFourLast": info.weekFourLast
     }).success(function(data) {
         $scope.show_form = true;
         if (data == true) {
             getInfo();
         }
     });
 }

}]); }]);

How can I integrate the javascript code in input ng-model to allow me to change the date showed? 如何将javascript代码集成到input ng-model以允许我更改显示的日期?

I solved the problem with THIS script. 我用这个脚本解决了这个问题。

I have one tiny problem. 我有一个小问题。 After I select date range in an input and hit UPDATE button, the new date will not be written in database. 在输入中选择日期范围并单击UPDATE按钮后,新日期将不会写入数据库。

In order to write in database my selected date, I have to copy manually the new date from input and paste it again to the same input. 为了将我选择的日期写到数据库中,我必须手动从输入中复制新日期并将其再次粘贴到同一输入中。

HTML: HTML:

<form class="form-horizontal alert alert-warning" id="editForm" ng-submit="UpdateInfo(currentUser)" hidden>
<input type="text" name="daterange" class="form-control" ng-model="currentUser.weekOneFirst" value="{{currentUser.weekOneFirst}}" >
</form>

jQuery script: jQuery脚本:

<script type="text/javascript">
$(function() {
    $('input[name="daterange"]').daterangepicker({
        "locale": {
        "format": "DD-MM-YYYY",
        "separator": " | ",
        "applyLabel": "Confirmă",
        "cancelLabel": "Anulează",
        "fromLabel": "De la",
        "toLabel": "La",
        "customRangeLabel": "Custom",
        "weekLabel": "S",
        "daysOfWeek": [
            "Du",
            "Lu",
            "Ma",
            "Mi",
            "Jo",
            "Vi",
            "Sa"
        ],
        "monthNames": [
            "Ianuarie",
            "Februarie",
            "Martie",
            "Aprilie",
            "Mai",
            "Iunie",
            "Iulie",
            "August",
            "Septembrie",
            "Octombrie",
            "Noiembrie",
            "Decembrie"
        ],
        "firstDay": 1
    },
    });
});
</script>

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

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