jquery-ui – I want to enter the characters of the era while using the datepicker of jQuery UI

Question: Question:

I have a textbox that applies the DatePicker widget of jQuery UI, but I want to be able to enter the era in it.
Specifically, I would like to allow character input in the following formats.
"H26 / 4/1"
"H26 / 4/1"

However, if you use datepicker in a text box (input [type = text]), you can enter numbers, but you cannot enter era symbols such as H.
It would be best if we could get rid of this input restriction, but is that possible?
If I can do that, I'm thinking of converting the format of the Christian era with an event like a change or blur in the text box …

In addition, I found a modified version so that the era name can be selected on the calendar widget, but the requirement is not selection but character input.

Answer: Answer:

I was able to input Japanese after datepicker() in both Firefox and IE …
You can replace the year this way.

Set constrainInput: false to allow alphabetic input.

  $(document).ready(function() {
    var format = 2;
        constrainInput: false,
        dateFormat: "yy/mm/dd",
        onSelect: function(e){
            var dateStr = $(this).val();
            var year = parseInt(dateStr.substr(2, 2), 10) + 12;
            var headStr = "";
            case 0: headStr = "H";    break;
            case 1: headStr = "h";    break;
            case 2: headStr = "平成"; break;
            $(this).val(dateStr.replace(/^[0-9]{4}/, headStr+year));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" />

日付:<input type="text" />
Scroll to Top