Setting a value to DateField by keyboard - Printable Version +- Curl Global Community (https://communities.curl.com) +-- Forum: Discussions (https://communities.curl.com/forumdisplay.php?fid=1) +--- Forum: General Curl questions (https://communities.curl.com/forumdisplay.php?fid=2) +--- Thread: Setting a value to DateField by keyboard (/showthread.php?tid=286) |
Setting a value to DateField by keyboard - alchimiste - 09-27-2011 Hi, I used DateField as below, the date format is YYYYMMDD Users want input the value by keyboard as displaying format, this is impossibe because DateField allows text with only DD/MM/YYYY format How can other format that we wish be allowed? Code: {DateField RE: Setting a value to DateField by keyboard - c-s - 09-27-2011 I suspect that you should actually be looking at date-format-spec. date-format-spec == DateFieldFormatSpec.iso seems to match your desired parse/format rules. If you have more complicated needs, you can ignore that and set parse-spec in addition to format-spec, but that is certainly more work. RE: Setting a value to DateField by keyboard - alchimiste - 09-27-2011 Thanks a lot.. I implement what users want with your help. The modified code as below: PHP Code: {DateField RE: Setting a value to DateField by keyboard - c-s - 09-28-2011 That's about right but I believe your indices are incorrect. Though the documentation for parse-spec is not entirely detailed on this point, the indices to return are selection indices, not character indices. The difference being that selection indices are to the left of the character indices in the string. This means that, for a fixed format of YYYYMMDD, you would return (0,4)(4,6)(6,8) instead of (0,3)(4,5)(6,7). Plus you should still set date-format-spec -- though this is not clear at all from the documentation. (Also you should set it first so that it doesn't override your parse-spec and format-spec.) Probably the documentation could be improved here, and I will make a note of that. Also I think some of your returned indices are incorrect even with the assumption of character indices. You can tell there's an issue by pressing up and down in the DateField; this should get you single year/month/day moves, but the selection is short by an index, so looks weird, and it can miss the desired change depending on where the caret index is. I haven't extensively tested this, but I think this reflects what you were aiming for: Code: {curl 7.0, 8.0 applet} Note that I changed the formatting somewhat and removed the extraneous StringBufs. As a note to others who might use this code, like the original code sample, it doesn't properly handle all possible DateField.separators, or unbalanced separators. For production, I would want to look at improving that aspect of parsing. RE: Setting a value to DateField by keyboard - alchimiste - 09-28-2011 Thanks again... When I read your reply first, I didn't understand what the selection that you said means. I've found that I can change year, month and day by pressing UP or DOWN key in DateFiel, and so I understand what you said. That's great and very interesting. I hope the documentation of Curl IDE would be more detailed. |