tonytomov / jqGrid

jQuery grid plugin
www.trirand.com
2.84k stars 1.2k forks source link

Date and Datetime fields when editing #997

Open unle70 opened 3 years ago

unle70 commented 3 years ago

Hello,

I'm working with revision 5.5.5 of jqGrid. Currently the documents do not mention support for column types "date" and "datetime-local" when editing. I have found by experience that actually those types CAN be used and can (almost) work well.

The only issue now is that the validator is rejecting the values. Looks like the validator is trying to use the "formatoptions.newformat" for validating. I believe this is not optimal. The format created by the browser is something like: "yyyy-mm-ddTHH-MM-SS" (note the "T" in the middle). The validator is always failing due to this. Probably there should be a separate parameter for input validation template.

I have been able to overcome this issue by using the custom validator. If and when possible, I would recommend adding proper support for these field types as I'm sure many users would love to use them.

tonytomov commented 3 years ago

Hello,

Thank you.

The validator works only with type of data and type time and not datetime.

I have added support in parseDate function to check date-time field, but it is not very well tested. This is something that really should be improved and I will make this possible this and next week.

Kind Regards

unle70 commented 3 years ago

Hi Tony,

That sounds just great. I have noticed another issue with this type of fields (datetime-local). When doing Form-Edit or Inline-Edit, the original column value is not properly copied to the edit field in the edit form. Fields of other types are set correctly, just this one is left blank.

Thanks.

tonytomov commented 3 years ago

Hello,

Can you please provide a example of that?

Thanks

unle70 commented 3 years ago

Hi Tony,

Providing an example is always a challenge for me. In my environment I have created a kind of "generator" on the server which automatically produces the client-side configuration. It produces a HUGE and very complicated code as it supports almost all the features that jqGrid has to offer (just for future flexibility). If I need to produce a demo code I cannot use this generator environment and have to start from zero and make it. I will try, but it might take some time.

Thanks, Udi

unle70 commented 3 years ago

Hi Tony,

Sorry again that I did not help with preparing the example for you debug this issue properly. In the meantime I think I can already understand why this is happening so if one day you get around to this, here is the issue:

It's exactly the same as the original problem I told you about (above). The datetime input expects this "T" as a separator between the date and time. In the main grid I'm using formatoptions/newformat: 'Y-m-d H:i'. This means the grid text has this "space" instead of a "T" (for readability). When you open the edit-form and copy the value to the INPUT fields, the default un-format does not replace this space back into "T". Then the $('input').val(grid-value) statement cannot process correctly. Now I have added my own custom un-format which simply replaces the space with a "T". Everything works fine after that.