warrenbuckley / YouTube-Umbraco

YouTube for Umbraco
12 stars 17 forks source link

Breaks when no OrderBy value is chosen #5

Open bjarnef opened 10 years ago

bjarnef commented 10 years ago

The Channel and OrderBy prevalues in config should be required (or have a default value in the code for e.g. orderBy = date).

Also see the issue here: http://our.umbraco.org/projects/backoffice-extensions/youtube/issues-help/55146-Breaks-when-no-OrderBy-value-is-chosen

When I added required validation for those two fields I expirienced it validated the fields, but I wasn't able to pick vidoes, because it return these errors:

TypeError: Cannot read property 'enableMin' of null TypeError: Cannot read property 'enableMax' of null

So I checked that minmax field wasn't null and set enableMin and enabledMax as default to false in case minmax is null.

package.manifest:

"prevalues": {
        "fields": [
          {
            "description": "Enter the Channel to display videos only for that channel",
            "key": "channel",
            "label": "Channel ",
            "view": "~/App_Plugins/YouTube/views/prevalues/YouTube.channelinfo.html",
            "validation": [
              {
                  "type": "Required"
              }                        
            ]
          },
          {
            "description": "Select the sort order for display videos",
            "key": "orderBy",
            "label": "Order By",
            "view": "~/App_Plugins/YouTube/views/prevalues/YouTube.orderby.html",
            "validation": [
              {
                  "type": "Required"
              }                        
            ]
          },

...

YouTube.js:

var isMinEnabled = $scope.model.config.minmax != null ? $scope.model.config.minmax.enableMin : false;

var isMaxEnabled = $scope.model.config.minmax != null ? $scope.model.config.minmax.enableMax : false;
warrenbuckley commented 10 years ago

Hey @bjarnef looks like you done all the hard work for me on this. I will make the changes suggested & re-test.

Thanks, Warren

warrenbuckley commented 10 years ago

OK this is three quarters done with Min & Max setting a default object rather than nulls if no value for the prevalue is saved (ie initial load of datatype)

Order by is now required with a HTML attribute on the select dropdown.