angular-ui-router#1.0.11 fire jarvis.widget.js warns "It looks like your using a class instead of an ID, dont do that!"

568 Views Asked by At

I use the SmartAdmin for angular, Recently I update Angular from 1.4.12 to angular v1.6.6, After that i discovery when i switch between state where is used JarvisWidget, the JavaScript library for the JarvisWidgets (more specifically, the lines 319-325 of the uncompressed jarvis.widget.js)

/**
  * Force users to use an id(it’s needed for the local storage).
  **/
  if (!$(‘#’ + self.objId).length) {
    alert(‘It looks like your using a class instead of an ID, dont do that!’);
  }

started alerting every time the page is opened. How can I avoid this alert (in a correct way) on pages with no JarvisWidgets without modifying this part of the JarvisWidget library? Why is this alert triggered in my case?

1

There are 1 best solutions below

0
On

The temporary solution until adapting to to new version of angular-ui-router#1.0.11 is revert back to angular-ui-router#0.3.2 then replace code as below:

// link function in directive in jarvisWidget.js

link: function(scope, element, attributes) {
  if(element.data('widget-color'))
    element.addClass('jarviswidget-color-' + element.data('widget-color'));

  element.find('.widget-body').prepend('<div class="jarviswidget-editbox"><input class="form-control" type="text"></div>');

  element.addClass('jarviswidget jarviswidget-sortable');
  $rootScope.$emit('jarvisWidgetAdded', {widget: element, id: attributes.id });
}

// Body of the jarvisWidgetAdded listener function in widgetGrid.js:

var widget = widgetPackage.widget;
var widgetId = widgetPackage.id;
if (widgetIds.indexOf(widgetId) == -1) {
  widgetIds.push(widgetId);
  $timeout(function () {
    setupWidgets(element, widgetIds)
  }, 100);
}

Please write an other solution!