We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10226
    • 412 Posts
    Is it possible to add a custom field to jot that is a date picker, similar to a TV? In my application of Jot, the entry date has zero relevance to the content and it is sorted via a custom date. At the moment the custom date is simply a text field.

    Thanks!
      • 1122
      • 209 Posts
      You can add to the Jot custom field and you can apply to it some sense of the date, but a full-fledged date behavior is impossible. The Jot stores additional (custom) fields in a separate table where all these fields are kept in textual format (name of the custom field may be up to 50 characters long and its value is of type text which means 64 KB chunk of data). Full-fledged date behavior needs a field to be the date itself or the so-called unixstamp.

      Provided that your users fill in your custom date field in strict format, YYYY-MM-DD, it will serve well for intended sorting, but you need, of course, to force your users in some way for strict format of their input. You can validate field with a regular expression
      &validate=`MyDate:^\d\d\d\d-\d\d-\d\d$`
      

      Above is a very basic suggestion for such a validation. The better your regex is the stricter format your users will be forced to.

      The detailed description of Jot’s parameters you can find at http://wiki.modxcms.com/index.php/Jot
        • 10226
        • 412 Posts
        Only two people will ever be using the system and the date format is understood so no issues there, and sorting it is a breeze.

        How does Jot store the default date fields? Could a core hack be an alternative?
          • 1122
          • 209 Posts
          The Jot snippet stores dates of four kinds: createdon, editedon, deletedon, publishedon (these are field names, self-explanatory, I guess). All dates are internally and automatically handled/maintained by the snippet. Dates are kept along with comments in main table "modx_jot_content" (while custom fields are placed into an associated table "modx_jot_fields" in textual format, as mentioned in my earlier post). These four dates are recorded into the database as Unix timestamps (an integer value that stands for number of seconds from Jan 1, 1970).

          I cannot explain you whether a core hack might be an alternative since assumptions/goals of your project/application are unclear for me.
            • 10226
            • 412 Posts
            All I need is the ability to enter a date that can be stored in unixtime and modified at will. In my application, records are not always entered on the date they occur. Or figure out how to use the text field style date and convert it to unixtime for further processing.
              • 1122
              • 209 Posts
              Your conversion may look like
              function date2unixtime($textdate) {
                # text date has MMDDYYYY format
                if (preg_match('/^(\d\d)(\d\d)(\d\d\d\d)$/', $textdate, $matches)) {
                  # text date splitted into month, day, and year parts -> conversion to unix timestamp
                  return mktime(0, 0, 0, $matches[1], $matches[2], $matches[3]);
                }
                # failure -> incorrect format of text date
                return FALSE;
              }
              

              Done.
                • 10226
                • 412 Posts
                Sorry I’m so dumb with this stuff... so is that phx or a snippet.. and how to I feed it my param?
                  • 1122
                  • 209 Posts
                  This is a pure php function that might be used in many contexts. In order to use it as snippet, create new snippet, name it "date2unixtime", paste into snippet’s code field...
                  <?php
                  # text date has MMDDYYYY format
                  if (preg_match('/^(\d\d)(\d\d)(\d\d\d\d)$/', $textdate, $matches)) {
                    # text date splitted into month, day, and year parts -> conversion to unix timestamp
                    return mktime(0, 0, 0, $matches[1], $matches[2], $matches[3]);
                  }
                  # failure -> incorrect format of text date
                  return FALSE;
                  ?>
                  

                  ... and use it as...
                  [!date2unixtime? &textdate=`03102009`!]