3

I am attaching datepicker to a span but I want the popup style and functionality that you get from attaching to an input. I can change the css to position:absolute, but the datepicker does not close on escape, blur, select, etc. Do I have to manually handle the popup functionality (such as closing the datepicker) or is there a way to disable inline mode?

script

//Inline Editing: Dates
$('.date span').live('click', function () {
    var $date = $(this);
    $date.datepicker({
        onSelect: function (val, dp) {
            var $job = $date.closest('.job');
            var data = {
                entityTypeName: 'Sale',
                entityId: $job.attr('data-id'),
                propertyName: $date.attr('data-property-name'),
                propertyValue: val
            };
            $.post(urlSaveProperty, data, function (r) {
                if (r == 'ok') {
                    $date.effect('highlight');
                } else {
                    alert(r);
                    $date.val('error');
                }
            });
        }
    });
    $(this).datepicker('show');
});

cshtml

<td class="contract-date date">
    <span data-property-name="ContractDate" >
        @job.ContractDate.SimplifyThisYear()
    </span>
</td>
4
  • 1
    is there a way to disable inline mode? As far as i know, there isn't. Datepicker is designed to work with an input:text. WHat you could do, is transform a span on click event into a input and then trigger the datepicker. Or roll your own version of datepicker. Here is an example of the first option
    – rusln
    Commented Jun 28, 2013 at 21:46
  • @rusln that is an interesting idea, but it seems element tag names are readonly. So a new input would not retain the properties of the original span. I don't see any other options though so I will probably try it out with a hidden input. Thanks for the idea.
    – Benjamin
    Commented Jul 1, 2013 at 19:08
  • wait, what ? the spans are readonly, or ? readonly is only for the end user, you can still manipulate the values of readonly elements with code
    – rusln
    Commented Jul 1, 2013 at 19:47
  • @rusln No I meant the tagName property is readonly. I was responding to your idea to "transform a span into an input". I don't think it is possible to actually transform one element into another. Maybe that is not really what you meant anyway. However, creating an input on the fly and then destroying it when done should do the trick. Thanks.
    – Benjamin
    Commented Jul 1, 2013 at 20:05

0