onehilltech / ember-cli-mdc

ember-cli addon for material-components-web
Apache License 2.0
44 stars 15 forks source link

mdc-textfield: TypeError if value is null #11

Closed mloar closed 5 years ago

mloar commented 5 years ago

The recent change d55fcae introduced a bug where a TypeError will occur in _checkValue if value is null. if (document.activeElement !== input && value !== undefined && value !== value.value) {

hilljh82 commented 5 years ago

@mloar There seems to be a typo in the conditional statement that I need to check. But, do you have an example that is causing the issue? Is it when value=null in the template?

mloar commented 5 years ago

In my case I'm binding value to a DS.attr('string') on a model. My backend returns nulls in the JSON, which get passed through the model into the template. Probably not the best design, but hasn't been a problem otherwise.

hilljh82 commented 5 years ago

@mloar Thanks, this is helpful.

hilljh82 commented 5 years ago

@mloar 0.74.17 has the fix.

jamesstaub commented 5 years ago

I am experiencing a similar problem with mdc-textfield 0.78. if i pass a null property to value (like when a related model has not resolved.

Screen Shot 2019-05-09 at 10 47 05 AM

hilljh82 commented 5 years ago

@jamesstaub This is the same problem, but in a different location. It seems that 2.0.0 has made some changes at the foundation level that is not liking null values.

hilljh82 commented 5 years ago

@jamesstaub Upon further investigation, this is actually a completely different issue altogether. The underlying material-components-web does not like a null value. Ideally, the underlying foundation component should check for null value before trying to set the character count. I am going to submit a patch to material-components-web to handle this scenario.

In the meantime, I am trying to figure out how to best handle this situation. Not setting the value to null in the foundation component could lead to unwanted behavior, such as not reseting the input. Translating null values to an empty string could present a problem if the native input triggers a change event—resulting the bound attribute to convert from null to an empty string. I will get the latter approach a try and see if this is a viable solution.

hilljh82 commented 5 years ago

0.78.1 patch contains a fix for this problem.

jamesstaub commented 5 years ago

awesome thank you!