Home Forums WoodMart support forum Add Clear Button on Search Forms

Add Clear Button on Search Forms

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #564984

    baranozdemir.com
    Participant

    Hello, I want to add a clear button to search forms. When I click on the button the input value will be removed.

    I added this one but it doesn’t work well:

    function baran_add_clear_icon_on_search_forms() {
    	?>
    	<style>
    		.clear-icon:before {
    			content: "\f112";
    			font-family: "woodmart-font";
    			color: black;
    			display: flex;
    			align-items: center;
    			justify-content: center;
    			font-size: 20px;
    		}
    
    		.clear-icon {
    			position: absolute;
    			right: 30px;
    			top: 50%;
    			transform: translateY(-50%);
    		}
    	</style>
    	<script type="text/javascript">
    		jQuery('form.woodmart-ajax-search').append('<div class="clear-icon"></div>');
    		let clearIcon = jQuery('.clear-icon');
    		let formInput = jQuery('form.woodmart-ajax-search').find('input[type="text"]');
    	
    		clearIcon.on('click', function(e) {
    			e.preventDefault();
    			
    			formInput.val('').attr('value','');
    			if (formInput.val().length <= 0) {
    				jQuery(this).hide();
    			}
    		});
    	
    		if (formInput.val().length > 0) {
    			clearIcon.show();
    		} else {
    			clearIcon.hide();
    		}
    	
    		formInput.on('change keydown paste input', function(e) {
    			let length = e.target.value.length;
    			if (length > 0) {
    				clearIcon.show();
    			} else {
    				clearIcon.hide();
    			}
    		});
    	</script>
    	<?php
    }
    add_action( 'wp_footer', 'baran_add_clear_icon_on_search_forms' );
    

    You can test it on mobile.

    • This topic was modified 5 months, 3 weeks ago by baranozdemir.com. Reason: Added new info
    #565158

    Hello,

    Sorry but there is no option in Theme Settings available for that.

    It requires customizations and this is beyond our limitations and support policy.

    Regards.
    Xtemos Studios

    #565159

    baranozdemir.com
    Participant

    Thank you.

    #565160

    Most Welcome!!!.

    I’m so happy to hear you are pleased with the Theme and Support. XTEMOS strives to deliver the best customer experience, and it makes our day to hear we have accomplished that.

    We count ourselves lucky to have you as a customer. You can always reach us at any time. We are always here to help you.

    Thanks for contacting us.
    Have a great day.

    Topic Closed.
    Best Regards.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Add Clear Button on Search Forms’ is closed to new replies.