Copied to clipboard

Flag this post as spam?

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


  • Laurent Lequenne 122 posts 247 karma points
    May 25, 2018 @ 10:19
    Laurent Lequenne
    0

    Array of dates are modified after save in the backend

    I have a strange behavior, I created a custom property editor to handle multiple dates. The dates are stored in a json array with format of YYYY-MM-DDTHH:mm:ss

    It's working fine, at the first save, the data is correctly stored in the database, my usync file is correct. But somehow the content is modified in the process and changed to YYYY-MM-DD HH:mm:ss , so if I save my data again without reloading the page, my dates are corrupted.

    If I reload my content, the data stays in the correct format.

    It looks like a bug... IF someone has an idea what could change this data ?

    Thank you

    angular.module("umbraco").controller("Consilium.MultidatePicker", function ($scope, dialogService) {
    
        $scope.model.value = $scope.model.value || [];
    
        if (!($scope.model.value instanceof Array))
            $scope.model.value = [];
    
        $scope.displayDates = [];
    
        for (var i = 0; i < $scope.model.value.length; i++) {
            // We reset back to the right format... Something is removing the format outside of the scope
            // Data is well saved with right format at the first save, but it is transformed (on second save, the format won't be correct anymore)
            $scope.model.value[i] = moment($scope.model.value[i]).format("YYYY-MM-DDTHH:mm:ss");
            $scope.displayDates.push(moment($scope.model.value[i]).format("YYYY-MM-DD"));
        }
    
        $scope.addDate = function () {
                dialogService.open({ template: '/App_Plugins/Consilium.MultidatePicker/views/Dialog.html', show: true, callback: done, dialogData: null });
    
            function done(data) {
                if (data) {
                    var date = moment(data).format("YYYY-MM-DDTHH:mm:ss");
                    var found = 0;
    
                    $.each($scope.model.value, function (idx, val) {
                        if (val == date) {
                            found = 1;
                        }
                    });
    
                    if (!found) {
                        $scope.model.value.push(date);
                        $scope.displayDates.push(moment(data).format("YYYY-MM-DD"));
                    }
                }
            }
        };
    
    
    });
    
Please Sign in or register to post replies

Write your reply to:

Draft