Untitled
unknown
plain_text
7 months ago
1.3 kB
5
Indexable
function add_upc_dash_fix_script() {
?>
<script>
jQuery(document).ready(function($) {
// Get the input element
var $searchInput = $('#b2bking_bulkorder_search_text_indigoid');
// Function to add the dash if missing
function formatUpcInput(input) {
var value = input.val();
// Check if input starts with 'upc' (case insensitive) without a dash
if (value.match(/^upc(?!-)[a-zA-Z0-9]/i)) {
// Add the dash after 'upc'
value = value.replace(/^(upc)([a-zA-Z0-9])/i, '$1-$2');
input.val(value);
}
}
// Add event handlers
if ($searchInput.length) {
// On blur (when user leaves the field)
$searchInput.on('blur', function() {
formatUpcInput($(this));
});
// On key press (for real-time formatting)
$searchInput.on('input', function() {
formatUpcInput($(this));
});
// On form submission
$searchInput.closest('form').on('submit', function() {
formatUpcInput($searchInput);
});
}
});
</script>
<?php
}
add_action('wp_head', 'add_upc_dash_fix_script');Editor is loading...
Leave a Comment