About Bootsreap automatic prompt typeahead bug

Source: Internet
Author: User

Bootstrap is an open-source front-end development framework that provides a number of plugins that can be used by developers, including many templates and styles.

During the previous period, when the study was completed automatically, a problem was found in the bootstrap auto-prompt, and then the problem was solved in detail.

First of all, the company's projects are BOOTSTRAP2.

Problem Description: In the Chinese input method, when the input box that has been declared as Typeahead is entered, when the ENTER key is pressed, the existing content will not be automatically prompted.

Solution: Mainly this time the input method captures our keys will appear in Chinese input some hints, such as Sogou's words hint. Of course, there may also be a Sogou prompt box blocking our auto-complete prompt box. If the input is correct, when you press ENTER, we should have a prompt for our ideal state. But not at the moment. We look at the code snippet bootstrap about Typeahead's source discovery:

Here's how to press the key:

 keyup: function  (e)  {    switch  (E.keycode)  {         CASE 40:        CASE 38:         case 16:         case 17:        case 18:             break;        case 9:         case 13:             if  (!this.shown) return;             this.select ();            break;         case 27:             if  (!this.shown) return;            this.hide ();             break;         default:            this.lookup ( )     }    e.stoppropagation (),  e.preventdefault ()}

When you look at it, you'll find that pressing ENTER here is the event of choice, and our Typeahead prompt does not select the result we want, which is obviously not what we want to do with the selection event.

Here's my revised code:

keyup: function  (e)  {    switch  (E.keycode)  {         case 40:        case 38:         case 16:        case  17:        case 18:             break;        case 9:         //case 13:             if  (!this.shown) return;             this.select ();            break;         case 27:             if (!this.shown) return;            this.hide ();             break;         case 13:            if   (!this.shown)  {this.lookup (); return;}             this.select ();             break;        default:             this.lookup ()     }     e.stoppropagation (),  e.preventdefault ()}

Look at the code will find that we have removed the original processing of enter, a new branch to deal with our method. The main logic is: If the prompt box is not displayed, then we need to find the following data, display the prompt box. If it does, we execute the selection event.

Solve the problem. The main problem may be that bootstrap developers may not have faced the event of entering Chinese to perform enter, so they did not find the problem, or, BOOSTRAP3, have already been repaired.

This article is from the "Silent Chen Gui" blog, please make sure to keep this source http://snaile.blog.51cto.com/8061810/1727139

About Bootsreap automatic prompt typeahead bug

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.