Tuesday, January 21, 2025
HomejQueryOne-Click on Enter Clearing with jQuery - Clearable Enter

One-Click on Enter Clearing with jQuery – Clearable Enter


ClearableInput is a tiny jQuery plugin that robotically provides a CLEAR button to the textual content fields you specify. This can assist your customers rapidly erase the content material they entered with a single click on.

The plugin works nicely for each particular person enter fields and a number of associated textual content fields. For instance, if in case you have fields for a buyer’s title, ID, and tackle, you may arrange the plugin to clear all three with a single click on. 

The best way to use it:

1. Add jQuery library and ClearableInput plugin’s recordsdata to your webpage.


<!-- jQuery is required -->
<script src="/path/to/cdn/jquery.min.js"></script>

<!-- jQuery ClearableInput Plugin -->
<script src="jquery.clearableinput.js"></script>
<hyperlink href="clearableinput.css" rel="stylesheet" />

2. Choose the enter fields you need to make clearable and name the .clearableInput() perform.


$(perform(){ 
  $('.myInput').clearableInput();
});

3. The plugin additionally helps you to clear a number of associated textual content fields without delay. You may group these inputs utilizing the data-clrgrp attribute in your HTML:


<enter id="username" sort="textual content" class="clearable-input" data-clrgrp="myGroup" />
<enter id="e mail" sort="e mail" data-clrgrp="myGroup" />
<textarea id="message" data-clrgrp="myGroup"></textarea>

4. Alternatively, you may specify which fields to clear utilizing the clear_items choice throughout init:


$('#username').clearableInput({
  clear_items: ['username', 'email','message']
});

The way it works:

The Clearable Enter Plugin works by extending jQuery’s performance. It first units up default choices, together with the CSS selector for enter fields (enter.clearable-input) and an array to retailer IDs of things to be cleared (clear_items). You may override these defaults while you initialize the plugin.

The plugin wraps every goal enter discipline with a <span> aspect that has the category clearable-span. This span acts as a container. Then, it provides a <div> aspect with the category clearable-icon proper after the enter discipline. This div accommodates the “X” icon that customers click on to clear the enter.

The plugin displays the enter discipline for modifications. If the enter discipline accommodates textual content, it makes the clear icon seen. If the enter discipline is empty, it hides the clear icon.

When a consumer clicks the clear icon, the plugin first clears the principle enter discipline it is hooked up to. When you specified components to clear utilizing the clear_items choice, the plugin loops by way of these IDs and clears every corresponding aspect. When you didn’t use the clear_items choice however the enter discipline has a data-clrgrp attribute, the plugin appears to be like for different components with the identical data-clrgrp worth and clears them as nicely. Lastly, it updates the visibility of the clear icon, hiding it because the enter discipline is now empty.


This superior jQuery plugin is developed by nalindaDJ. For extra Superior Usages, please test the demo web page or go to the official web site.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments