We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How would I add a tooltip to all datepickers in a project?

Hi,
I have a large ASPNET Core project that contains a lot of date picker input fields.  I have been requested to add a tooltip that displays the selected date in the users Long Date format to all date fields.  Is it possible to do this globally?  or would I have to do add a tooltip to each field?  An chance you could provide a coded example as I am new to web development?
Thanks in advance

3 Replies

Berly Christopher September 6, 2017 04:31 PM UTC

Hi Allan, 
 
Thanks for contacting Syncfusion support. 
 
We have checked with your query. We suggest to use “htmlAttributes” API to set the tooltip for the DatePicker component initially. By using this API, you can add custom attribute to the DatePicker component. Please refer the below code example. 
Index.cshtml: 
 
 
@{ IDictionary<string, object> htmlAttr = new Dictionary<string, object>(); 
    string value = "hi"; 
    htmlAttr.Add("title", value);     
} 
 
<ej-date-picker id="DatePick1" html-attributes="htmlAttr></ej-date-picker> 
       
 
Also, if you are using multiple datepicker in the page, you can achieve your requirement (“I have been requested to add a tooltip that displays the selected date in the users Long Date format to all date fields”) by using our “change” event in your application. This will update your tooltip text whenever the value changes in DatePicker component. 
 
We suggest you to use ej.format() in your sample that will used to convert the date value as the desired format. Then you have to store this date value in the private variable and set this value to the “htmlAttributes” API by using the below code example. 
Index.cshtml: 
  <ej-date-picker id="DatePick2" change="onChange"></ej-date-picker> 
  <ej-date-picker id="DatePick3" change="onChange"></ej-date-picker> 
  <ej-date-picker id="DatePick4" change="onChange"></ej-date-picker> 
<script> 
         function onChange(args) 
         { 
             var date = ej.format(this.model.value, "dddd, d MMMM, yy", this.model.locale); 
             this.option("htmlAttributes", { title: date }); 
         } 
     </script>   
                 
For your convenience, we have prepared the sample based on your requirement. Please get the sample from the below location. 
  
To know more about our API’s, events and methods please refer the below API Documentation link. 
 
Please refer the below link to kow more about our DatePicker component in ASP.NET Core. 
 
If still you are facing issues please get back to us with more details that will help us to provide exact solution. 
 
Regards, 
Berly B.C 


AN Allan Nielsen September 6, 2017 11:06 PM UTC

Thank you for your quick response. Simple and well explained.


Berly Christopher September 7, 2017 01:06 PM UTC

Hi Allan, 
Thanks for the update. Please check with the provided sample and get back to us if you need any further assistance on this. 
Regards, 
Berly B.C 
 

Loader.
Live Chat Icon For mobile
Up arrow icon