Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery ui datepicker - altfield as a div rather than input

I am using the altfield and altformat options on the jquery ui datepicker to display a friendly date to the user, while having the date formatted for the database in a hidden field. The only thing is, I don't want the date shown to the user in an input box (visually it suggests they can type in it), I just want it shown as text. I know I could style an input box so it doesn't look like it is one, but I'd rather just use a div and update the text. However, it only seems to work with an input field, if you set it to a div id, it does nothing.

Has anyone overcome this issue?

like image 681
ianmcn Avatar asked Dec 05 '22 05:12

ianmcn


1 Answers

I've gotten it to display in a div using this in the onSelect:

onSelect: function(dateText, inst) {
//formatDate Requires a new date object to work
      var myDate = new Date(dateText);

//Set a new var with different format to use
      var newFormat = $.datepicker.formatDate("DD, d MM, yy", myDate);
//Choose the div you want to replace
      $("#yourselctorhere").html(newFormat);
    }
  });
like image 117
matthewb Avatar answered Jan 25 '23 09:01

matthewb