mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	zjquery: Tell user why using tags as selector is invalid.
Like using $('input') is too broad a selector and shouldn't
be used in the codebase. With this error messages, contributors
can easily understand that now.
			
			
This commit is contained in:
		
				
					committed by
					
						
						Steve Howell
					
				
			
			
				
	
			
			
			
						parent
						
							269457c58b
						
					
				
				
					commit
					2b8921bf67
				
			@@ -29,7 +29,14 @@ function verify_selector_for_zulip(selector) {
 | 
			
		||||
        (selector.includes("[") && selector.indexOf("]") >= selector.indexOf("["));
 | 
			
		||||
 | 
			
		||||
    if (!is_valid) {
 | 
			
		||||
        throw new Error("Invalid selector: " + selector + " Use $.create() maybe?");
 | 
			
		||||
        // Check if selector has only english alphabets and space.
 | 
			
		||||
        // Then, the user is probably trying to use a tag as a selector
 | 
			
		||||
        // like $('div a').
 | 
			
		||||
        if (/^[ A-Za-z]+$/.test(selector)) {
 | 
			
		||||
            throw new Error("Selector too broad! Use id, class or attributes of target instead.");
 | 
			
		||||
        } else {
 | 
			
		||||
            throw new Error("Invalid selector: " + selector + " Use $.create() maybe?");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user