Announcement

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

    Make chooserDate blank by default

    I have a form with a dateitem that I would like t0 display as empty by default and *not* save any value to the datasource or to save null when saveData() is called.*unless* the user enters a date. This is different than the default behavior where the date chooser displays the current date and calling saveData() on the form stores the current date to the datasource.

    I'm wondering if there is a simple way to get this behavior. My searching of the docs has not turned up anything so far.

    Thanks

    #2
    Dates can be null if you useTextField - see the doc for that attribute, which explains behavior.

    Comment


      #3
      Set useTextField:true on your DateItem and you will get a text field instead of MDY pickers. Then it can be empty by default.

      With MDY pickers you would have to do something like detect changes and clear out the value if no changes had happened, right before save.

      Comment


        #4
        So I tried calling form.setValue immediately followed by form.saveData, but it does not work as hoped. It still saves todays date to the datasource. Similar outcome by calling formClearValue().


        this.form.setValue("thankyouLetterDate",null);
        this.form.saveData(function() {this.clearValues()});

        Comment


          #5
          That's because null is not a valid value unless you have set useTextField:true, as we explained above.

          Comment


            #6
            Hi rpoyner,

            perhaps in DataSource.get()-requestTransformer?

            Best regards
            Blama

            Comment


              #7
              No, that's overkill. If you wanted the MDY pickers, which again we would advise against because it is not a good UE if the field is allowed to be null, you would simply set the DateItem.name to something that is not the real name of the field and then on the changed event, copy the value over to the real fieldName via setValue().

              Comment


                #8
                Wanted to say thanks.
                I went with using a dummy DateItem with the defaultValue set to 1970/01/01 and set the changed callback to copy the value to the real field. Haven't rolled it out to the users yet, but hopefully the 1970 date will be enough of a cue that they need to set the date.

                Comment

                Working...
                X