• Many sites need automatic typing. Why not change your JavaScript function inside file username-availability-checker.js to look like this?

    var debounce__BDUAChecker;
    jq( document).on( 'keyup', _BDUAChecker.selectors, function() {
    	if(debounce__BDUAChecker) clearTimeout(debounce__BDUAChecker);
    	
    	var $__this = this,
    		$this = jq( $__this ),
    		$wrapper = $this.parent('.username_checker');
    	
    	jq( '.loading', $wrapper ).css( {display:'block'} );
    	
    	debounce__BDUAChecker = setTimeout(function(){
    
    		if( ! $wrapper.get(0) ) {
    			$wrapper = create_wrapper( $__this );
    		}
    		
    		jq( '.name-info', $wrapper ).empty();//hhide the message
    		//show loading icon
    		jq( '.loading', $wrapper ).css( {display:'block'} );
    		
    		var user_name = $this.val();
    		
    		jq.post( ajaxurl, {
    			action: 'check_username',
    			cookie: encodeURIComponent(document.cookie),
    			user_name: user_name
    			},
    			function( resp ) {
    				
    				if( resp && resp.code != undefined && resp.code == 'success' ) {
    						show_message( $wrapper, resp.message, 0 );
    				} else {
    					show_message( $wrapper, resp.message, 1 );
    				}
    			},
    			'json'	
    	 
    		);
    	},250);
    });//end of keyup
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Brajesh Singh

    (@sbrajesh)

    Hi,
    Thank you for the suggestion and the code.

    Using blur even helps us avoid extra http requests and it suits the user experience. Keyup is nice but more suitable for auto suggest kind of setup and not on username where people need o make their mind about their choice.

    For the time being, we will be staying with blur but if there are more people interested in using keyup, we will add your code.

    Thank you
    Brajesh

    Thread Starter Ivijan-Stefan Stipic

    (@ivijanstefan)

    Hi,

    Make one checkbox optional for users and just give it as choice blur or keyup. I added debounce in my code which prevents ajax from being called immediately while typing but it would be good from 250 (as I give on example) to set the timeout to 650.

    Users like a bunch of small and smart options so I suggest this as one of those.

    Best regards!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Why not change AJAX check to keyup and avoid blur?’ is closed to new replies.