2

I have a custom list of "requests" which need to accommodate a required time range for a single date (among other fields), so I added "start" and "end" columns of date and time type. I used designer to create a custom new form and displayed these two fields side by side. With jquery, I hid the textbox and calendar of the "end" field, so the user sees a single textbox and calendar for the date and two sets of time dropdown menus. Whenever the date is changed in the visible date textbox, I push it to the hidden date textbox with jquery.

When I click save, the form is validated and the hidden "end" date textbox loses its value. Why is the value lost and how can I keep it?

As a workaround, I'm sure I could make the "end" column not required and set its date within ItemAdding and ItemUpdating event receivers, but would prefer to resolve this on the client side if possible.

2
  • I'd get into firebug and see what all happens under the hood using a regular calendar control. Maybe jQuery is succesfully setting a form field value on the surface, but, the underlying viewstate gobbletygook isn't being notified of a field change in the same way as if a user had interacted with the control.
    – bkwdesign
    Commented Dec 11, 2012 at 20:27
  • Yeah, I think my above comment is on the money. I've seen this before. It's all about the viewstate. Answer is going to be at another link found on this site: forums.asp.net/t/1596330.aspx/1
    – bkwdesign
    Commented Dec 11, 2012 at 20:33

1 Answer 1

0

If you've disabled the EndDate element, it won't be saved. If thats the case, the trick is to re-enable it in the PreSaveAction().

1
  • Thank you! I ended up just leaving the EndDate element enabled since it is hidden. I think I would have to handle ALL validation myself in the PreSaveAction if I wanted that element to be visible and disabled. Right now, I let SP validate additional required fields and that seems to be called after the PreSaveAction(). So if any other fields fail their validation, the EndDate would remain enabled.
    – Erin
    Commented Dec 14, 2012 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.