Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Matthieu Nelmes 102 posts 385 karma points
    Jan 13, 2016 @ 17:04
    Matthieu Nelmes
    0

    moment.locale making my life a living hell

    Trying to implement a DatePicker in a custom section in the Back Office.

    keep getting moment.locale is not a function. in the browser console

    Here's what I'm working with:

    datepicker controller

    angular.module("umbraco").controller("MyApp.DatepickerController",
        function ($scope, assetsService, angularHelper, $element) {
    
            //setup the default config
            var config = {
                language: 'en',
                pickDate: true,
                pickTime: false,
                useSeconds: true,
                format: "YYYY-MM-DD",
                icons: {
                    time: "icon-time",
                    date: "icon-calendar",
                    up: "icon-chevron-up",
                    down: "icon-chevron-down"
                }
            };
    
            $scope.config = angular.extend(config, $scope.config);
    
            function applyDate(e) {
                angularHelper.safeApply($scope, function () {
                    // when a date is changed, update the model
                    if (e.date) {
                        $scope.property.Value = e.date.format("YYYY-MM-DD");
                    }
                });
            };
    
            var filesToLoad = ["lib/datetimepicker/bootstrap-datetimepicker.js"];
    
            assetsService.load(filesToLoad).then(
                function () {
                    $element.find("div:first")
                        .datetimepicker($scope.config)
                        .on("dp.change", applyDate);
                });
        });
    

    view

                                <umb-control-group label="Arrival Date">
                                    <div class="controls controls-row">
                                        <div class="umb-editor umb-datepicker" ng-controller="MyApp.DatepickerController" id="from">
                                            <div class="input-append date datepicker" style="position: relative;">
                                                <input name="from" data-format="dd/MM/yyyy" type="text" ng-model="room.ArrivalDate" />
                                                <span class="add-on">
                                                    <i data-date-icon="icon-calendar"></i>
                                                </span>
                                            </div>
                                        </div>
                                    </div>
                                </umb-control-group>
    

    package.manifest

    {
        javascript: [
            '~/Umbraco/lib/moment/moment-with-locales.js',
            '~/App_Plugins/BookingsAdmin/datepicker.controller.js'
        ],
        css: [
            '~/App_Plugins/BookingsAdmin/BookingsAdmin.style.css'
        ]
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft