Usage
This function runs automatically, so it is not called manually. Is this incorrect?
Source File
Located in /assets/js/modules/search.js on line 331.
No Hooks
This function does not have any filters or actions available. Request one?nebula.searchValidator = function(){ //Wrap in requestIdleCallback when Safari supports it if ( jQuery('.input.search').length ){ jQuery('.input.search').each(async function(){ await nebula.yield(); if ( jQuery(this).val() === '' || jQuery(this).val().trim().length === 0 ){ jQuery(this).parent().children('.btn.submit').addClass('disallowed'); } else { jQuery(this).parent().children('.btn.submit').removeClass('disallowed').val('Search'); jQuery(this).parent().find('.input.search').removeClass('focusError'); } }); jQuery('.input.search').on('focus blur change keyup paste cut', async function(e){ await nebula.yield(); let thisPlaceholder = ( jQuery(this).attr('data-prev-placeholder') !== 'undefined' )? jQuery(this).attr('data-prev-placeholder') : 'Search'; if ( jQuery(this).val() === '' || jQuery(this).val().trim().length === 0 ){ jQuery(this).parent().children('.btn.submit').addClass('disallowed'); jQuery(this).parent().find('.btn.submit').val('Go'); } else { jQuery(this).parent().children('.btn.submit').removeClass('disallowed'); jQuery(this).parent().find('.input.search').removeClass('focusError').prop('title', '').attr('placeholder', thisPlaceholder); jQuery(this).parent().find('.btn.submit').prop('title', '').removeClass('notallowed').val('Search'); } if ( e.type === 'paste' ){ jQuery(this).parent().children('.btn.submit').removeClass('disallowed'); jQuery(this).parent().find('.input.search').prop('title', '').attr('placeholder', 'Search').removeClass('focusError'); jQuery(this).parent().find('.btn.submit').prop('title', '').removeClass('notallowed').val('Search'); } }); jQuery('form.search').on('submit', function(){ if ( jQuery(this).find('.input.search').val() === '' || jQuery(this).find('.input.search').val().trim().length === 0 ){ jQuery(this).parent().find('.input.search').prop('title', 'Enter a valid search term.').attr('data-prev-placeholder', jQuery(this).attr('placeholder')).attr('placeholder', 'Enter a valid search term').addClass('focusError').trigger('focus').attr('value', ''); jQuery(this).parent().find('.btn.submit').prop('title', 'Enter a valid search term.').addClass('notallowed'); return false; } return true; }); } };
Override
To override or disable this JavaScript function, simply redeclare it with the exact same function name. Remember: Some functionality is conditionally loaded via dynamic imports, so if your function is not overriding properly, try listening for a DOM event (described below).
For non-module import functions:
nebula.searchValidator = function(){ //Write your own code here, leave it blank, or return false. }
For dynamically imported module function overrides:
jQuery(window).on('load', function(){ nebula.searchValidator = function(){ //Write your own code here, leave it blank, or return false. } });
Custom Nebula DOM events do also exist, so you could also try the following if the Window Load listener does not work:
jQuery(document).on('nebula_module_loaded', function(module){ //Note that the module variable is also available to know which module specifically was imported if ( typeof nebula.searchValidator === 'function' ){ nebula.searchValidator = function(){ //Write your own code here, leave it blank, or return false. } } });