weixin_39579726
2021-01-12 16:43 阅读 8

Typeahead - can't clear input field on select

I am using async example from showcase. I've set:


<input null ...>

and selecting something doesn't clear the input.

该提问来源于开源项目:valor-software/ngx-bootstrap

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

14条回答 默认 最新

  • weixin_39604139 weixin_39604139 2021-01-12 16:43

    +1. And it seems that the ngmodel is bind to the matches, there's no way to clear the text in input

    点赞 评论 复制链接分享
  • weixin_39604139 weixin_39604139 2021-01-12 16:43

    I have a workaround for this situation. Inside changeModel function, we can set valueStr to '' to clear the input box.

    点赞 评论 复制链接分享
  • weixin_39657662 weixin_39657662 2021-01-12 16:43

    can you show what do you mean by changeModel ? I really need it badly

    点赞 评论 复制链接分享
  • weixin_39604139 weixin_39604139 2021-01-12 16:43

    there's a changeModel function inside typeahead directive, change valueStr to '' to clean the input box

    点赞 评论 复制链接分享
  • weixin_39657662 weixin_39657662 2021-01-12 16:43

    can you please tell me the the markup ?

    
    <input class="form-control">
    

    is this okay ?

    and in component

    
    onChange(val){
       val = " ";
    }
    

    or is it something different ?

    点赞 评论 复制链接分享
  • weixin_39604139 weixin_39604139 2021-01-12 16:43

    no, the workaround is to change the source code.

    点赞 评论 复制链接分享
  • weixin_39657662 weixin_39657662 2021-01-12 16:43

    =| how ? can you guide me please or tell me the code that worked for you ?

    点赞 评论 复制链接分享
  • weixin_39604139 weixin_39604139 2021-01-12 16:43

    actually I copied the src folder from this repo and put it into my src folder and reference the component as usual way.

    点赞 评论 复制链接分享
  • weixin_39989973 weixin_39989973 2021-01-12 16:43

    It would be nice to get a fix for this.

    点赞 评论 复制链接分享
  • weixin_39595320 mizore 2021-01-12 16:43

    It would indeed

    点赞 评论 复制链接分享
  • weixin_39571403 weixin_39571403 2021-01-12 16:43

    I would also like to get a way of clearing user selections

    点赞 评论 复制链接分享
  • weixin_39777213 weixin_39777213 2021-01-12 16:43

    +1

    点赞 评论 复制链接分享
  • weixin_39720510 eternal? 2021-01-12 16:43

    mm, best way is (ngModelChange)="$event.target.value = ''"

    点赞 评论 复制链接分享
  • weixin_39978444 weixin_39978444 2021-01-12 16:43

    Also you can get reference to input field via ViewChild and clear its value when typeaheadOnSelect is triggered

    点赞 评论 复制链接分享

相关推荐