Announcement

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

    set DateItem default value to empty

    I have

    Code:
    DateItem dateofbirth=new DateItem("dateofbirth");
    how can I set an empty value for dateofbirth? it is showing the current date as default! This is causing my users to have today as their birthday! I want the defaul to be null.

    #2
    Unfortunately the picker version of DateItem doesn't support a "null" date. You'll have to use DateItem.setUseTextField(true) for this.

    Sanjiv

    Comment


      #3
      I see, thanks Sanjiv.


      Mutaz

      Comment


        #4
        DateItem can't support null or space

        Hi,
        We have also planned and used ( 3 selectable boxes for date) and at testing phase realized that it doesn't support null or space.

        It will nice if smartgwt can provide this feature as for example date of death have to null or space until the user selects a value.

        Please let me if there are plans to enhance the DateItem to provide this functionality in the future so that we plan and design for future release our product.

        Thanks
        Seeni

        Comment


          #5
          Either setUseTextField(true) or provide a separate checkbox or similar for null. Other possibilities like having the user set all three pickers to blank would be worse UI than either of the existing options.

          Comment


            #6
            I've been struggling with this as well:

            Code:
            closedDate = new DateItem(DIDOrderField.CLOSED_DATE.getName());
            closedDate.setTitle(DIDOrderField.CLOSED_DATE.getDisplayTitle());
            closedDate.setUseTextField(true);
            closedDate.setEnforceDate(false);
            closedDate.setValue((String)null);
            When the closedDate DateItem is rendered it is always populated with today's value. I just can't seem to set it to empty, no matter what I try.

            Comment


              #7
              You seem to be struggling with something unrelated. When useTextField is true, DateItems support null values, as can be seen pervasively in the Showcase.

              Comment


                #8
                Originally posted by Isomorphic
                You seem to be struggling with something unrelated. When useTextField is true, DateItems support null values, as can be seen pervasively in the Showcase.
                Actually, the source of my problem seems to be the fact that the form this dateItem is part of is backed by a dataSource; i.e.:

                Code:
                mainForm = new DynamicForm();
                mainForm.setDataSource(dataSource);
                closedDate = new DateItem(DIDOrderField.CLOSED_DATE.getName());
                closedDate.setTitle(DIDOrderField.CLOSED_DATE.getDisplayTitle());
                closedDate.setUseTextField(true);
                
                mainForm.setFields(closedDate);
                If I comment out the
                Code:
                mainForm.setDataSource(dataSource);
                line, the field renders empty, as expected.

                Here is my datasource file:


                Code:
                <DataSource
                	ID="didOrder"
                	serverType="generic">
                	<fields>
                		<field name="id" type="sequence" hidden="false" primaryKey="true"/>
                		<field name="title" type="text" title="Title" length="255" required="true"/>
                		<field name="type" type="enum" title="Type" length="20" required="true"/>
                		<field name="status" type="enum" title="Status" length="20" required="true"/>
                		<field name="requestedDate" type="date" title="Request Date" required="true"/>
                		<field name="closedDate" type="date" title="Closed Date" required="false"/>
                		<field name="account" type="text" title="Account" valueXPath="account/id" required="true"/>
                		<field name="accountName" type="text" title="Account" valueXPath="account/company" required="false"/>
                		<field name="csa" type="text" title="CSA" valueXPath="csa/id" required="false"/>
                		<field name="csaName" type="text" title="CSA" valueXPath="concat(csa/account/username, ':', csa/id)"/>
                		<field name="createdBy" type="text" title="Created By" valueXPath="createdBy/userId" required="true"/>
                		<field name="createdByName" type="text" title="Created By" valueXPath="concat(createdBy/firstName, ' ', createdBy/lastName)" required="false"/>
                		<field name="assignedTo" type="text" title="Assigned To" valueXPath="assignedTo/userId" required="false"/>
                		<field name="assignedToName" type="text" title="Assigned To" valueXPath="concat(assignedTo/firstName, ' ', assignedTo/lastName)" required="false"/>
                		<field name="contactEmails" type="text" title="Contact Emails" multiple="true"/>
                		<field name="rejectedReason" type="text" title="Rejected Reason"/>
                		<field name="notes" type="text" title="Notes"/>
                		<field name="didIds" type="int" title="DIDs" multiple="true" required="true"/>
                	</fields>
                	
                	 <serverObject lookupStyle="spring" bean="didOrderDAO"/>
                	 
                </DataSource>
                I'm wondering now - do I need to set a default value of null or something in the ds.xml file?

                Comment


                  #9
                  Never mind, I found what the problem was. Apparently, I had to call DynamicForm.editNewRecord() or all the date fields would be populated with today's date.

                  Comment


                    #10
                    OK, so i'm bumping this thread since i'm having the same requirement.

                    I am using a form as a potential filter for data in a listgrid. I'm using the dateitem picklist like:

                    DateItem dateItem = new DateItem();
                    dateItem.setAttribute("selectorFormat", DateItemSelectorFormat.MONTH_YEAR);

                    But it always populates the item with today's values. I would like it to be empty by deafult so that i know if the user has selected anything, since i have other potential filtering values.

                    usetextfield() is not optimal either in my case, since i want the user to enter year and month, but the textfield requires a full date string...

                    Are there any plans of including the option to have an empty default value, for example like the comboboxitem?

                    Cheers
                    Last edited by mathias; 8 Feb 2011, 01:50.

                    Comment


                      #11
                      I'm facing a similar issue, and setting useTextItem is functional but not exactly what I want.

                      I'd like to make a custom FormItem that consists of a checkbox (with no label) and a dateItem (using the three drop boxes).

                      When the checkbox is ticked, the dateItem functions as normal. The getValue() of the formItem will return the current value of the dateItem.

                      When it is unticked, the dateItem is disabled and getValue() will return null.

                      I've done something similar where I've added a separate checkbox and dateItem as suggested above, but this is messy having to code this in whenever I want the functionality. I'd much rather be able to just call "new NullableDateItem(name, title)" or whatever.

                      I can easily code the logic for this, but I can't see how to code for the layout. E.g, I can't see how when subclassing FormItem, to but some other formItems into a HLayout or ToolStrip or whatever, and have that be the visual representation of the FormItem.

                      Could I get a pointer on how to do this? I'll gladly share the resulting code if anyone wants it.

                      Comment


                        #12
                        Take a look at CanvasItem

                        Comment


                          #13
                          Hopey_diswasher, did you create a custom component to do this then?

                          I have same issue in that the Date value coming from the server is null and the UI conditionally may show this field or not depending on the form state. So for example, the date comes in as null, is never shown on the UI and when update button is clicked and saveData is called, Today's date is sent over.

                          I can code some server side logic to handle this, but it means doing it everywhere we use a date and was hoping a version of DateItem would be available that allows nulls and still renders the same way as without nulls.

                          I will use the setTextField(true) if needed but would prefer to have the nice UI elements.

                          Thanks.

                          Comment

                          Working...
                          X