Search code examples
javascriptjqueryioscordovaphonegap-plugins

Phonegap iOS 10 input type "date" not able to show value


I am creating app in phonegap/cordova and i have created form with input type of - text, date. So

<input placeholder="DOB" type="date"  class="form-control profile-page-dob" >

Above html was supporting before iOS 10 but as i updated iphone 6s then native datepicker is display but value which i am giving to "type=date" is not displaying but value is there (when i checked through alert($(".profile-page-dob").val()) i.e. 1996-05-01 ).

If anybody expert got something Please let me know.

Thanks


Solution

  • I have just found some tricky way, because ios10 is showing value of selected date but placeholder is working then I just appended value in placeholder attribute using change,focusin & focusout function to handle datepicker value.

                $(".profile-page-dob").change(function(){
                    // alert(1)
                    $(this).attr('type','date')
                    $(this).attr('placeholder',$(this).val())
                    $(this).attr('value',$(this).val())
                    $(this).val($(this).val());
                    userDob = $(this).val();                       
                    // alert($(".profile-page").html())
                })
    
                $(".profile-page-dob").focusin(function(){
                    $(this).attr('type','date')
                    $(this).attr('placeholder',$(this).val())
                    $(this).attr('value',$(this).val())
                    $(this).val($(this).val())
                    userDob = $(this).val();             
                })
    
    
                $(".profile-page-dob").focusout(function(){
                    $(this).attr('type','date')
                    $(this).attr('placeholder',$(this).val())
                    $(this).attr('value',$(this).val())
                    $(this).val($(this).val())
                    userDob = $(this).val();                  
                })