This is a migrated thread and some comments may be shown as answers.

[Solved] DateTime value with .HiddenFor still draws datepicker calendar

1 Answer 564 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
ilker
Top achievements
Rank 1
ilker asked on 19 Jan 2012, 09:34 AM
Hello,

On my main page, there is .DisplayFor(m => m.Invoice.Date) and  HiddenFor(m => m.Invoice.Date); so that I store the value in a hidden input and show the read-only to the users.

Everything seems fine since I need a pop-up window that allows to edit the fields of entity. This pop-up form also includes .EditorFor(m => m.Invoice.Date) As the pop-up form is opened, there appears the calendar icon on the main page.

Before clicking pop-up, html in main page is:
<input id="Invoice_Date" type="hidden" value="11.01.2012 00:00:00" name="Invoice.Date">

After clicking pop-up extra div's and span's are added to main page's html as below:
<div class="t-widget t-datepicker">
<div class="t-picker-wrap">
       <input id="Invoice_Date" class="t-input" type="hidden" value="11.01.2012" name="Invoice.Date" autocomplete="off">
<span class="t-select">
</div>
</div>

A sample screenshot is attached.

1 Answer, 1 is accepted

Sort by
0
ilker
Top achievements
Rank 1
answered on 19 Jan 2012, 02:34 PM
The problem here is; the pop-up window tries to draw the div's and span's, but the page has already an input with the same name (for hidden input.)

So it draws the clickable calendar image, spans, divs directly to this hidden input, instead of the ones on the pop-up.

I solved the issue by changing the name of the hidden inputs on main page; and on post event i get these values from FormCollection and bind to model manually as below. (So that these values are still on the page when the page validation fails etc..)

[HttpPost]
public ActionResult Edit(InvoiceDocumentModel model, FormCollection fc = null)
{
    model.Invoice.Date = Convert.ToDateTime(fc["InvoiceDate"].ToString());
    model.Invoice.PaymentDate = Convert.ToDateTime(fc["InvoicePaymentDate"].ToString());
 
   .....

I think datepicker should try to look for the input's name in the same div; not on all html output. If the popup form's datepicker field looks for the input in the same div, it would find the correct input on pop-up, not the one on main page that popus is opened.

Regards,
Tags
Date/Time Pickers
Asked by
ilker
Top achievements
Rank 1
Answers by
ilker
Top achievements
Rank 1
Share this question
or