Ninja Forms add placeholder to the Date/Time field

·

·

You may be aware that the placeholder text for the default Date/Time field is not working on the front end of Ninja Forms. However, it is sometimes necessary to have it.

Ninja Forms placeholder text

To add the placeholder, add a custom CSS class like “cs_placeholder_text” as shown in the screenshot below.

Ninja Forms custom CSS class

Now add the following jQuery code to your child theme JavaScript file or try the Simple Custom CSS and JS plugin. Make sure to have the settings similar to the screenshot below.

jQuery(document).ready(function( $ ){
	$('.cs_placeholder_text .hour.extra').prepend('<option selected disabled>Hour Text</option>');
	$('.cs_placeholder_text .minute.extra').prepend('<option selected disabled>Minute Text</option>');
});

After that, if you check the front end, you will find that both placeholder texts have been added as the first option in both Date/Time input fields of Ninja Forms.

Ninja Forms add placeholder to the Date/Time field
placeholder preview

I added the “selected” and “disabled” attributes to the option field. This ensures that the new placeholder option is selected and disabled by default. Visitors will now have to choose a valid hour and minutes from the Date/Time field.

<option selected disabled>Hour Text</option>

Video tutorial:


Meet the author

Faisal Ahammad

I’m working as Support Engineer at Saturday Drive Inc (AKA Ninja Forms) and General Translation Editor (GTE) for the #bn_BD 🇧🇩 language. As an active contributor to WordPress and open-source projects, I have translated over 60 themes, plugins, and WordPress core. I also have a small YouTube channel where I share my knowledge.


Leave a Reply

Your email address will not be published. Required fields are marked *