material icon indicating copy to clipboard operation
material copied to clipboard

md-autocomplete: validation not working anymore in 0.10.0

Open r0b- opened this issue 11 years ago • 12 comments

https://material.angularjs.org/0.10.0/#/demo/material.components.autocomplete, floating label demo should have validation & messages.

Thanks Rob

r0b- avatar Jun 16 '15 19:06 r0b-

+1

monyprak avatar Jun 17 '15 06:06 monyprak

+1

mikedobrin avatar Jun 17 '15 14:06 mikedobrin

+1

rockclimber90 avatar Jun 17 '15 15:06 rockclimber90

+1

ninety7 avatar Jun 17 '15 22:06 ninety7

To fix for this is change getInputElement function

where ng-require=isRequired to @mdAutocompleteCtrl.isRequired

                function getInputElement() {
                    if (attr.mdFloatingLabel) {
                        return '\
        <md-input-container flex ng-if="floatingLabel">\
          <label>{{floatingLabel}}</label>\
          <input type="search"\
              id="fl-input-{{$mdAutocompleteCtrl.id}}"\
              name="{{inputName}}"\
              autocomplete="off"\
              ng-required="$mdAutocompleteCtrl.isRequired"\
              ng-minlength="inputMinlength"\
              ng-maxlength="inputMaxlength"\
              ng-disabled="$mdAutocompleteCtrl.isDisabled"\
              ng-model="$mdAutocompleteCtrl.scope.searchText"\
              ng-keydown="$mdAutocompleteCtrl.keydown($event)"\
              ng-blur="$mdAutocompleteCtrl.blur()"\
              ng-focus="$mdAutocompleteCtrl.focus()"\
              aria-owns="ul-{{$mdAutocompleteCtrl.id}}"\
              aria-label="{{floatingLabel}}"\
              aria-autocomplete="list"\
              aria-haspopup="true"\
              aria-activedescendant=""\
              aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/>\
          <div md-autocomplete-parent-scope md-autocomplete-replace>' + leftover + '</div>\
        </md-input-container>';
                    } else {
                        return '\
        <input flex type="search"\
            id="input-{{$mdAutocompleteCtrl.id}}"\
            name="{{inputName}}"\
            ng-if="!floatingLabel"\
            autocomplete="off"\
            ng-required="$mdAutocompleteCtrl.isRequired"\
            ng-disabled="$mdAutocompleteCtrl.isDisabled"\
            ng-model="$mdAutocompleteCtrl.scope.searchText"\
            ng-keydown="$mdAutocompleteCtrl.keydown($event)"\
            ng-blur="$mdAutocompleteCtrl.blur()"\
            ng-focus="$mdAutocompleteCtrl.focus()"\
            placeholder="{{placeholder}}"\
            aria-owns="ul-{{$mdAutocompleteCtrl.id}}"\
            aria-label="{{placeholder}}"\
            aria-autocomplete="list"\
            aria-haspopup="true"\
            aria-activedescendant=""\
            aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/>\
        <button\
            type="button"\
            tabindex="-1"\
            ng-if="$mdAutocompleteCtrl.scope.searchText && !$mdAutocompleteCtrl.isDisabled"\
            ng-click="$mdAutocompleteCtrl.clear()">\
          <md-icon md-svg-icon="md-close"></md-icon>\
          <span class="md-visually-hidden">Clear</span>\
        </button>\
            ';
                    }
                }
            }
        };

SriramaDanturthi avatar Jun 18 '15 22:06 SriramaDanturthi

+1 And how to set max-length constraint on md-autocomplete?

Clan-Utility avatar Jun 30 '15 01:06 Clan-Utility

fyi @Sriram143, looks like there's a PR in process https://github.com/angular/material/pull/3366

longrunningprocess avatar Jul 02 '15 13:07 longrunningprocess

I solved it like this: .directive('isRequired', ['$compile', function($compile) { return { restrict: 'A', terminal: true, priority: 1000, link: function(scope, element) { element.removeAttr('is-required'); if (scope.isRequired) { element.attr('required', 'required'); } $compile(element)(scope); } }; }]) From: billy clark [email protected] To: angular/material [email protected] Cc: Mike Dobrin [email protected] Sent: Thursday, July 2, 2015 3:54 PM Subject: Re: [material] md-autocomplete: validation not working anymore in 0.10.0 (#3293)

fyi, looks like there's a PR in process #3366— Reply to this email directly or view it on GitHub.

mikedobrin avatar Jul 02 '15 14:07 mikedobrin

and isRequired on the scope is set by the parent  directive From: billy clark [email protected] To: angular/material [email protected] Cc: Mike Dobrin [email protected] Sent: Thursday, July 2, 2015 3:54 PM Subject: Re: [material] md-autocomplete: validation not working anymore in 0.10.0 (#3293)

fyi, looks like there's a PR in process #3366— Reply to this email directly or view it on GitHub.

mikedobrin avatar Jul 02 '15 15:07 mikedobrin

This is resolved in master and will in the 0.10.1 release.

robertmesserle avatar Jul 06 '15 20:07 robertmesserle

This doesn't seem to be working still.

he's my code:

<md-autocomplete required md-input-id="input_boundBallot" class="md-primary"
        ng-disabled="ac.isDisabled"
        md-input-name="boundStuff"
        md-no-cache="ac.noCache"
        md-autoselect="ac.autoSelect"
        md-select-on-match="ac.selectOnMatch"
        md-selected-item="ac.selectedStuff"
        md-search-text-change="searchTextChange(ac.searchText)"
        md-search-text="ac.searchText"
        md-selected-item-change="selectedItemChange(item)"
        md-items="item in searchStuff(ac.searchText)"
        md-item-text="item.display"
        placeholder="Select an item"
        ng-value="ac.searchText"
        md-min-length="0">
    <md-item-template>
        <span md-highlight-text="ac.searchText" md-highlight-flags="^i">{{item.display}}</span>
    </md-item-template>
    <md-not-found>
        No matches found for "{{ac.searchText}}".
    </md-not-found>
    <div ng-messages="aform.boundStuff.$error">
        <div ng-message="required">This field is required</div>
    </div>
</md-autocomplete>

I don't think there's anything wrong with the code.

Trying with latest master 5722449b372604fc2231f73140a44094c3a94cf8

evoker avatar Aug 05 '15 12:08 evoker

You might want to check if your aform is actually there. Print it out {{ aform.boundStuff }}

pencilcheck avatar Sep 02 '15 06:09 pencilcheck