Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Question about year/month-only DateItem

    I just noticed a strange error in my javascript console when I'm creating a DateItem where I only want year/month to be visible. I do it like this:

    Code:
    SelectItem props = new SelectItem();
    props.setHidden(true);
    props.setReadOnly();
    props.setDisabled(true);
    props.setVisible(false);  
    
    yearMonthItem = new DateItem();
    yearMonthItem.setShowPickerIcon(false);
    yearMonthItem.setTitle("Month/Year");
    yearMonthItem.setDaySelectorProperties(props);
    It works fine, but I get this in the console:

    DateItem.setDaySelectorProperties(): the SelectItem passed has already been applied to an Object; unable to apply it again

    I don't get it since literally just created both objects. Can I do something to fix this?

    #2
    Are you trying to do something like what you get if you do dateItem.setInputFormat("MY")?

    Comment


      #3
      Hi, thanks for responding.

      No, that would still show the "day" dropdown. I want the user to only be able to see and select year and month. Actually, I think I originally had some tips to do it this way from one of your colleagues :)

      Comment


        #4
        Hi Isomorphic,

        I tried a similar thing back in 4.1p times for a private project and ended up building some own Widget and storing the information as incomplete date, either missing day or day and month.
        This was in the case that the birthdate of a person is only partly known.

        In the database I then checked for missing parts and set them to 15.xx.yyyy or 01.01.yyyy in a virtual column.
        I'm pretty sure that this is/was not best practice.
        Out of interest: If you do a dateItem.setInputFormat("MY"), what would be stored as day-part?

        Best regards
        Blama

        Comment


          #5
          Apologies - selectorFormat is the attribute you want. Does that work?

          Blama, if the field is a date, there is surely no way to store it, as a date, without a day in it - it's just a number.
          Last edited by Isomorphic; 8 Oct 2018, 07:42.

          Comment


            #6
            Ah, apologies - *what* would be stored as the day part - 01 is the answer to that.

            Comment


              #7
              Iso, that's more like it! Works great. I can't be sure of course, but I'd wager a guess that this function might not have been around when I originally did the approach using the SelectItem.

              Cheers!

              Comment


                #8
                Originally posted by Isomorphic View Post
                Ah, apologies - *what* would be stored as the day part - 01 is the answer to that.
                Ah yes, then this would not have worked for me as I needed to distinguish real birth dates like "1890-01-01" from ones like "1890-01-??" or "1890-??-??" which you would store all the same.
                I don't know what kind of Widget I used there, though, anymore. Most likely 3 SelectItems in a DynamicForm and some colSpan setting.

                Hopefully I can go back to that project some day - I think a solution with CanvasItem and a ChangedHandler and hidden fields would be way nicer than what I did back then.

                Best regards
                Blama

                Comment

                Working...
                X