md-chips with md-autocomplete inside don't clear initial spaces characters #8750
Comments
I originally fixed that for the default chips in 2d020e1, but it seems like we didn't notice the same issue on the autocomplete. |
@robertmesserle The correct fix would be to disable ngTrim on the autocompletes input element, but I guess some developers are insisting on ngTrim enabled. I thought about disabling I also thought about adding a ngModel parser / formatter to overwrite the trimmed value, but that didn't work either. Any suggestions / ideas? (Probably setting ngTrim to disabled by default) @crisbeto Maybe you have an idea as well. |
I believe that ngTrim only trims the model value, but not the text in the input. Isn't the issue here that the input value isn't being trimmed? In that case we could do something like this: function getValue(value) {
return value ? value.trim() : value;
}
ctrl.$formatters.unshift(getValue);
ctrl.$parsers.unshift(getValue); @devversion my guess as to why the parser/formatter didn't work for you is that it should be applied to the inner input that has |
Yeah, it only trims the ngModel of the input element. In the chips component, we are loading the input value / chipBuffer from the ngModel. Yes, I had the exact same approach, but it didn't work, because the formatters, parsers won't be triggered, when a user enters a space. Not sure, where ngTrim is affecting that. About your guess, It will be definitely applied to the autocompletes input. Edit: https://github.com/angular/angular.js/blob/master/src/ng/directive/input.js#L1131-L1153 |
I had a similar issue with the parsers not firing for spaces, when I was working on the textarea. I ended up binding an Another option could be setting the |
I just had a discussion with @robertmesserle. Rob suggested, that we check the cursor position on backspace for the chips, instead of checking the inputs value. By checking the cursor position, we will not have to modify the ngModel / trimming on the autocomplete component and it would run independently with the standalone version of the autocomplete. (Weird sounding here) This would also improve the UX, because if you move your cursor to the start of the input and you press backspace, it should focus the previous chip. Once the cursor selection will be to hacky, we will probably fallback to the Thanks again. |
* Currently we check the truthyness of the chipBuffer, to confirm that the user is at the beginning of the chip input. Once he is at the beginning, we select and focus the previous chip, so the user can keep deleting the chips. * Checking for truthyness is not working, because Angular is trimming all ngModel values for the autocomplete and default chip input. This caused issues, where users can't delete their spaces in the input anymore. Checking the cursor position is more appropriated here, and works without affecting the autocomplete. This allows the autocomplete to work independently without any changes with the `md-chips` component. Fixes angular#8750
Actual behavior:
Steps to reproduce the issue:
Angular Versions:
Additional Information:
The text was updated successfully, but these errors were encountered: