Announcement

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

    Smart GWT 4.1 -- set DateItem default value to empty

    Code:
     DateItem dateItem=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 default to be null.

    I tried using DateItem.setUseTextField(true); But still showing the default date.

    Aslo i tired using dateItem.setDefaultValue(false); But still it not showing null.
    Is there a way i can show null by default.


    Thanks
    Ramesh Reddy Etta.

    #2
    Have you tried setDefaultValue(null)?

    Comment


      #3
      Yes I tried that as well, but still it is showing the default value to todays Date. please see the whole code.

      Code:
       
                       DateItem dateItem = new DateItem("dateofbirth");
      		dateItem.setSelectOnFocus(true);
      		dateItem.setUseTextField(true);
      		dateItem.setUseMask(true);
      		dateItem.setDefaultValue(false);

      Comment


        #4
        setDefaultValue(false) isn't a valid call. You would need setDefaultValue(null).

        But that aside, this is not reproducible - the default value for a DateItem with setUseTextField(true) is already null, and you can see this working in the online showcase here: http://www.smartclient.com/smartgwt/showcase/#form_controls_various

        Comment


          #5
          Directlly calling setDefaultValue(null) is giving compilation error in Eclipse "The method setDefaultValue(String) is ambiguous for the type DateItem";

          So i did tried to use like this
          Code:
                          String str = null;
          		dateItem.setDefaultValue(str);

          Comment


            #6
            Just don't call setDefaultValue() at all if you don't want a defaultValue. If you're still struggling, compare your code to that used by the sample in the showcase that we just linked to.

            Comment


              #7
              I think I found where the problem is. When I add dateItem.setName("dateofBirth)"; I am seeing this issue.

              But when i just set title and do not set name, i see an empty value. Do you know if there is an issue with setName(..) method of dateitem in 4.1?

              Comment


                #8
                This isn't a known issue - if you think there's a problem with the framework, please provide a stand-alone, minimal test-case that demonstrates the issue.

                Comment


                  #9
                  Could you let me know, how i can create a stand-alone, minimal test case or is this Ok if i can provide an Entry Point java class demonstrating this issue?

                  Comment


                    #10
                    Yes, that's all we need - an onModuleLoad() with no dependencies to third-party components or server-based data - you don't appear to need data for this test-case, but if you do for future test-cases, use a clientOnly dataSource.
                    Last edited by Isomorphic; 24 Jul 2014, 05:54.

                    Comment


                      #11
                      I also have this problem when the ListGridRecord was edited by:
                      form.editRecord(rec);

                      but when record was created on the same form the problem does not exists. For example:
                      The user created record where date = null. In DB was date = null but when user try to edit this record this date = currentDate!

                      I was trying to do anything:
                      DateItem dateItem = new DateItem("date","Sample date")
                      dateItem.setUseTextField(true);
                      String defaultDateValue = null;
                      dateItem.setDefaultValue(defaultDateValue );

                      and
                      dateItem.setUseTextField(true);
                      String defaultDateValue = null;
                      dateItem.setDefaultValue(defaultDateValue );

                      and
                      dateItem.setUseTextField(true);
                      Date defaultDateValue = null;
                      dateItem.setDefaultValue(defaultDateValue );

                      and
                      dateItem.setDefaultValue(false);

                      and
                      dateItem.setAutoComplete(AutoComplete.NONE);

                      and
                      dateItem.setDefaultChooserDate(null);

                      and the others. I tried everything..



                      When user did not change values during edition in the form the date should be also does not changed!


                      For example as above. User has birthday = null but afert editing birthday = currentDate. Is does not sense.


                      sample.ds.xml:
                      <field name="date type="date" title="Sample date" />

                      Chrome(Latest), Firefox(24.2.0)
                      SmartClient Version: v10.0p_2015-05-27/Enterprise Deployment (built 2015-05-27)
                      Last edited by TFKable2; 28 May 2015, 00:36.

                      Comment


                        #12
                        If the date delivered from the server is null, you will not need a setDefaultValue() call. But if the value delivered from the server is not actually null, then no call to setDefaultValue() can possibly correct the problem, because the defaultValue will never replace a non-null current value!

                        You need to look at what is *actually* coming from your server - the most direct way is to use the RPC tab in the Developer Console to see the server's response as JSON.

                        Comment


                          #13
                          Thanks for quick reply Isomorphic.

                          In my opinion what you wrote it makes sense.

                          I checked what is in the JSON response. Now I see that in the row where in database is null in this column in the JSON response this field does not exists - simply there is no field with this name in JSON response.

                          In case where in database column is not null(for instance: sample_date=2015-05-27) in JSON response I see: sample_date:"2015-05-27".

                          So looks like everything works great but during editing this row, in the form i see that sample_date = current_date! I want to have empty because in database is null. There is no value.




                          I added fresh(new) date field without any dependecies in the client/server side code.

                          Configuration is as simple as possible:

                          final DateItem simpleDateField = new DateItem("Simple date field");
                          simpleDateField .setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATE);
                          simpleDateField .setWidth(100);
                          simpleDateField .setTitle("Simple date field");
                          simpleDateField .setUseTextField(true);

                          and no code on the server side. Just plain ds.xml file with serverType="sql"
                          <DataSource ID="sample_ds" serverType="sql" dataSourceVersion="1" dbName="sample" tableName="sample_ds" useAnsiJoins="true" >

                          <field name="sample_date" type="date" title="Sample date" />
                          Last edited by TFKable2; 28 May 2015, 04:38.

                          Comment


                            #14
                            This behavior is not acceptable for the bussiness client because when user want to edit row changed nothing and click save action then sample_date is updated from null to current date!

                            Comment


                              #15
                              We're not reproducing this problem, and if it was a real framework issue, we'd expect lots and lots of people reporting it.

                              We would normally suggest that you try to create a minimal, standalone test case replicating the problem, but you can already see right here that straightforward use of the SQLDataSource does not have this issue.

                              So you need to look closely at your code and find the difference from normal usage.

                              Comment

                              Working...
                              X