allow edit in datepicker control

Hi support, in JS1 i can, for a DatePicker control, set the allow-edit="false" to deny the field edit  to the user and permit to choice the date only with selector. It's possible to achieve the same in the JS2 ?

Thanks
Stefano

3 Replies

PK Prem Kumar Madhan Raj Syncfusion Team July 2, 2018 11:11 AM UTC

Hi Stefano, 

Thanks for contacting Syncfusion Support. 

Yes we can restrict entering value in the DatePicker input element by adding readonly attribute to the input element of the component by using the created event as shown in the below code snippet. 

<ejs-datepicker id="datepicker" created="onCreate"></ejs-datepicker> 
 
<script> 
    function onCreate(args){ 
       var proxy = this; 
        this.element.setAttribute("readonly", true); 
        this.inputWrapper.container.addEventListener("click", function (args) { 
            var obj = document.getElementById("datepicker").ej2_instances[0];       
                obj.show() 
        }); 
    } 
</script> 

Once readonly attribute is enabled, the input element becomes unable to edit and you can select a value only by opening the popup element. For your convenience, we have also attached the sample in the below link. Please check it. 


Regards, 

Prem Kumar M


SC Stefano Capobianco July 4, 2018 07:44 AM UTC

Thanks Prem, your solution work very well. Isn't possible to introduce an option like for the JS1 control ?

Thanks
Stefano


PK Prem Kumar Madhan Raj Syncfusion Team July 6, 2018 01:20 PM UTC

Hi Stefano, 

Thanks for the update. 

Yes, we have considered to provide allowEdit support for DatePicker component with our upcoming Volume 2 2018 SP1 release to be rolled out by the end of this month. Please be patience until then. 

Regards, 

Prem Kumar M 


Loader.
Up arrow icon