Copied to clipboard

Flag this post as spam?

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


  • Phil Wheeler 4 posts 24 karma points
    Jan 20, 2014 @ 11:06
    Phil Wheeler
    0

    Set Umbraco Property Editor Input to jQueryUI Datepicker

    I'm close but still can't quite get this to work.

    I have a new custom property editor that is loading correctly and is doing almost everything expected until I try to set the text field to be a jQuery UI element.

    As soon as I add a directive in Angular for setting it to call the jQuery UI datepicker function, I get the following error suggesting it hasn't loaded the jQueryUI script library correctly:

    TypeError: Object [object Object] has no method 'datepicker'

    Trouble is, I can't see where I should be adding it as the logical places (to my mind, at least) seem to make no difference. Here is the code in full:

    function MultipleDatePickerController($scope, assetsService) {
    
        //tell the assetsService to load the markdown.editor libs from the markdown editors
        //plugin folder
        //assetsService
        //    .load([
        //        "http://code.jquery.com/ui/1.10.4/jquery-ui.min.js"
        //    ])
        //    .then(function () {
        //        //this function will execute when all dependencies have loaded            
        //    });
    
        //load the seperat css for the editor to avoid it blocking our js loading
        assetsService.loadCss("/css/jquery-ui.custom.min.css");
    
        if (!$scope.model.value) {
            $scope.model.value = [];
        }
    
        //add any fields that there isn't values for
        //if ($scope.model.config.min > 0) {
        if ($scope.model.value.length > 0) {
            for (var i = 0; i < $scope.model.value.length; i++) {
                if ((i + 1) > $scope.model.value.length) {
                    $scope.model.value.push({ value: "" });
                }
            }
        }
    
        $scope.add = function () {
            //if ($scope.model.config.max <= 0 || $scope.model.value.length < $scope.model.config.max) {
            if ($scope.model.value.length <= 52) {
                $scope.model.value.push({ value: "" });
            }
        };
    
        $scope.remove = function (index) {
            var remainder = [];
            for (var x = 0; x < $scope.model.value.length; x++) {
                if (x !== index) {
                    remainder.push($scope.model.value[x]);
                }
            }
            $scope.model.value = remainder;
        };
    
    }
    
    var datePicker = angular.module("umbraco").controller("AcuIT.MultidateController", MultipleDatePickerController);
    
    datePicker.directive('jqdatepicker', function () {
        return {
            restrict: 'A',
            require: 'ngModel',
            link: function (scope, element, attrs, ngModelCtrl) {
                $(function () {
                    element.datepicker({
                        dateFormat: 'dd/mm/yy',
                        onSelect: function (date) {
                            scope.$apply(function () {
                                ngModelCtrl.$setViewValue(date);
                            });
                        }
                    });
                });
            }
        }
    });
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies