Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Please help with jQuery UI Auto-Complete and CSS Scope!

Featured Replies

Hey everyone, I have a very aggravating problem, and I can't figure it out - enough time wasted.

 

I have an input with an ID of "#queryCountry" on it. There is jQuery that is adding the Auto Complete functionality to this input. On this page, I also use UI Tabs. I've styled the tabs how I want them (using jQuery UI styles, but they are in a separate style sheet), however the styles we are using for the Auto Complete screw up my tabs.

 

Solution: Use a CSS scope to target only the Auto Complete field.

 

Great. So in my UI CSS file, I add a CSS scope before each declaration of ".jqueryUI". In the HTML, I wrapped the form containing the "#queryCountry" input in a div with that class, like so:

 

<div class="jqueryUI">
    <form name="rateSearch" method="post" action="#">
         <input type="text" id="queryCountry" name="queryCountry" class="searchRateInput ui-autocomplete-input" autocomplete="off" placeholder="Type country name" />
    </form>
</div>

When I visit the page and try the form, the tabs keep their style how I want them. The auto complete function works, but the auto complete list of items is totally unstyled. If I remove the scope in the CSS, the auto complete list looks how I want it, and the tabs get all screwed up.

 

I don't see how this could be this hard. I've tried so many things and nothing is working. The styles within the scope aren't being read. It's an ASP.net site if that matters.

 

My ideas:

 

1. Does it matter when the auto complete function is called during the page load? Maybe it's activating before the html is being rendered?

2. When I inspect the auto compelte list element, it's showing up at the very bottom of the page with some inline styles added to it (I assume to position it under the input). This would mean it's not actually IN my scoped div. What's the point of scoping an element if it doesn't show up inside that div?? I can't get rid of the inline styles, the JS is creating those.

 

Any help is greatly appreciated. I'll do hacks, edit the JS, whatever it takes. I don't think this should be that hard. Hopefully I'm an idiot and this is an easy fix.

 

Thanks,
Steve

  • Author

Here is a snippet of the CSS:

 

.jquery .ui-menu {
	list-style: none;
	padding: 2px;
	margin: 0;
	display: block;
	outline: none;
}
.jquery .ui-menu .ui-menu {
	margin-top: -3px;
	position: absolute;
}
.jquery .ui-menu .ui-menu-item {
	margin: 0;
	padding: 0;
	width: 100%;
}
.jquery .ui-menu .ui-menu-divider {
	margin: 5px -2px 5px -2px;
	height: 0;
	font-size: 0;
	line-height: 0;
	border-width: 1px 0 0 0;
}
.jquery .ui-menu .ui-menu-item a {
	text-decoration: none;
	display: block;
	padding: 2px .4em;
	line-height: 1.5;
	min-height: 0; /* support: IE7 */
	font-weight: normal;
}
  • Author

I figure this out, in case anyone stumbles upon this same problem.

 

As I suspected, the auto-generated content was showing up at the bottom of the page, not within my scoped div. So I added the following jQuery AFTER calling the auto-complete.

 

$(".ui-autocomplete ").wrap('<div class="jqueryUI" />');

I had tried this earlier - but I had put it before calling the auto-complete, and I was wrapping around the input, not the auto-complete code generated by the javascript. Here is a page that helped me see what code is generated: http://jquery-ui.googlecode.com/svn/tags/1.8.4/docs/autocomplete.html

 

Hope this helps someone else!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.