Permalink
Browse files

bug: callAttached called only the first registered MdlComponent

  • Loading branch information...
MikeMitterer committed Jul 21, 2015
1 parent 16d7acb commit f21c2e85b01c1b3f377ec3f641d6a7fee5e4edf3
@@ -109,18 +109,25 @@ class MaterialTextfield extends MdlComponent {
/// Update text field value.
void change(final String value) {
if (value != null && value != _relaxedInput.value) {
int selStart = (_relaxedInput as dom.InputElement).selectionStart;
int selEnd = (_relaxedInput as dom.InputElement).selectionStart;
if (value != null) {
_relaxedInput.value = value;
(_relaxedInput as dom.InputElement).setSelectionRange(selStart,selEnd);
}
_updateClasses();
}
/// Returns text field value
String get value => _relaxedInput.value;
/// Update text field value
void set value(final String value) {
_relaxedInput.value = value;
_updateClasses();
change(value);
}
//- private -----------------------------------------------------------------------------------
View
@@ -46,9 +46,11 @@ MdlComponent mdlComponent(final dom.HtmlElement element,final Type type) {
void _listNames(var jsElement) {
final Logger _logger = new Logger('mdlcore.mdlComponent._listNames');
final List<String> componentsForElement = (jsElement[_MDL_WIDGET_PROPERTY] as String).split(",");
final List<String> componentsForElement = (jsElement[_MDL_COMPONENT_PROPERTY] as String).split(",");
_logger.info("Registered Component for $element:");
componentsForElement.forEach((final String name) {
_logger.warning("Registered Component $name for $element");
_logger.warning(" -> $name");
});
}
@@ -58,8 +60,7 @@ MdlComponent mdlComponent(final dom.HtmlElement element,final Type type) {
if(element.id != null && element.id.isNotEmpty) {
id = element.id;
}
throw "$element is not a MdlComponent!!! (ID: $id)";
throw "$element is not a MdlComponent!!! (ID: $id, ${element.classes}, ${element.dataset['upgraded']})";
}
String typeAsString;
@@ -92,7 +93,7 @@ MdlComponent mdlComponent(final dom.HtmlElement element,final Type type) {
_listNames(jsElement);
throw "$element is not a ${typeAsString}-Component!!!\n(ID: ${element.id}, class: ${element.classes})\n"
"These components are available: ${jsElement[_MDL_COMPONENT_PROPERTY] as String}";
"These components are available: ${jsElement[_MDL_COMPONENT_PROPERTY] as String}";
}
/// Calls the MdlComponents attached-function for the given [element] and all it's childrens
@@ -103,17 +104,17 @@ void callAttached(final dom.Element element) {
if(element is dom.HtmlElement) {
try {
final MdlComponent component = mdlComponent(element as dom.HtmlElement,null);
if(component != null) {
component.attached();
}
var jsElement = new JsObject.fromBrowserObject(element);
if(jsElement.hasProperty(_MDL_COMPONENT_PROPERTY)) {
final List<String> componentsForElement = (jsElement[_MDL_COMPONENT_PROPERTY] as String).split(",");
componentsForElement.forEach((final String componentName) {
// Ignore exception - it's OK here
} on String catch (e) {
final MdlComponent component = jsElement[componentName] as MdlComponent;
component.attached();
//_logger.info("$e");
});
}
}
// Iterate through all children
@@ -46,27 +46,23 @@ class MaterialModel extends MdlComponent {
MaterialModel.fromElement(final dom.HtmlElement element,final di.Injector injector)
: super(element,injector), _observerFactory = injector.get(ModelObserverFactory) {
}
@override
void attached() {
_scope = new Scope(this, mdlParentScope(this));
_init();
}
// Central Element - by default this is where mdl-model can be found (element)
// html.Element get hub => inputElement;
// - EventHandler -----------------------------------------------------------------------------
void handleButtonClick() {
_logger.info("Event: handleButtonClick");
}
//- private -----------------------------------------------------------------------------------
void _init() {
_logger.fine("MaterialModel - init");
//_logger.info("ParentScope: ${_scope.parentContext}");
_logger.info("ParentScope: ${_scope.parentContext}");
final String fieldname = element.attributes[_MaterialModelConstant.WIDGET_SELECTOR].trim();
_scope.context = _scope.parentContext;
@@ -90,9 +86,6 @@ void registerMaterialModel() {
// By default it's used as a class name. (<div class="mdl-model"></div>)
config.selectorType = SelectorType.ATTRIBUTE;
// Sets priority to 5 - means all Components get upgraded (priority 1) before this component
config.priority = 5;
componentHandler().register(config);
}
@@ -77,7 +77,7 @@ class MaterialProperty extends MdlComponent implements ScopeAware {
//- private -----------------------------------------------------------------------------------
void _init() {
_logger.info("MaterialProperty - init");
_logger.fine("MaterialProperty - init");
/// Recommended - add SELECTOR as class
element.classes.add(_MaterialPropertyConstant.WIDGET_SELECTOR);
@@ -106,6 +106,8 @@ class MaterialRepeat extends MdlTemplateComponent {
_addBorderIfInDebugMode(child,"red");
_logger.fine("Child to remove: $child Element ID: ${element.id}");
componentHandler().downgradeElement(child);
new Timer(new Duration(milliseconds: 30), () {
_items.remove(item);
child.remove();
@@ -41,7 +41,7 @@ class ModelObserverFactory {
} else {
throw new ArgumentError("${element} cannot be observed. Probably not a MdlComponent!");
throw new ArgumentError("${element} cannot be observed. Probably not a MdlComponent! Type: ${type}");
}
}

0 comments on commit f21c2e8

Please sign in to comment.