问题
I have a problem related to Date type which I'm using in smartgwt.
I set up the date to have the possibility to change it manually:
setAttribute("useTextField", true);
In Firefox and Chrome (and maybe other browsers , except Internet Explorer) if first I'm selecting a date with that pop-up calendar and than change it manually and then let the focus on the date field and going to save the document (actually is a form with multiple fields) the date changed manually it is lost, the date choosed from calendar it is saved. This is not happening in Internet Explorer.
In all browsers, if I select from Calendar a date and than change it manually and change the focus from it everythings goes fine - the manually changed date it is saved into db. Need some advices.
Thank you a lot.
Later edit:
I'm using com.smartgwt.client.widgets.form.fields.DateItem widget
.
DateItem date = new DateItem("A date");
date.setWidth(320);
date.setWrapTitle(false);
date.setAttribute("useTextField", true);
date.setAttribute("inputFormat", "yyyy/MM/dd");
date.setAttribute("displayFormat", "toJapanShortDate");
I'm adding this date on a DynamicForm:
DynamicForm form = new DynamicForm();
form.setFields(date);
and this form on a VLayout object:
VLayout editLayout = new VLayout(30);
editLayout.addMember(form);
The problem is reproducing in browsers like Firefox & Chrome when:
- I'm selecting first the date from calendar - say I'm selecting 2011/02/11
- I'm changing the day in 2011/02/12 manually - and I'm not changing the focus from this date field
- I'm pressing the 'Save' button.
After these steps the date is 2011/02/11 and not 2011/02/12 how it should be. In Internet Explorer browser did not happen - the date after the steps above is 2011/02/12!
Later edit:
I'm using a DataSource
for updating the data.
I'm having a UserObject
and in the userUpdate
method I'm creating this user object first with values from fields (which are on the DynamicForm
) - by calling the generateUserObjectFromForm()
method
UserObject user = generateUserObjectFromForm();
Here, in this method I'm doing something like:
user.setAddedDate(date.getValueAsDate())
,
but here the date.getValueAsDate()
value is the one selected from calendar, not the one modified manually.
I've tried also with:
date.getValue() //Fri Feb 11 00:00:00 GMT+200 2011
date.getValueField() // null
date.getValueAsDate() //Fri Feb 11 00:00:00 GMT+200 2011
date.getDisplayField() //null
date.getDisplayValue()//l2011/02/11
but none worked properly.
I'm using an request object (UserUpdateRequest
) for updating the user.
UserUpdateRequest
looks like:
public class UserUpdateRequest implements IsSerializable
{
UserObject user = null;
public UserUpdateRequest ()
{
}
public UserUpdateRequest (UserObject user)
{
this.user = user;
}
public UserObject getUser ()
{
return user;
}
}
final UserUpdateRequest request = new UserUpdateRequest(user);
and on the RPC user update method I'm sending this UserUpdateRequest
request.
Later edit (15 february):
I've discovered why is happening this issue related to focus, and this is because in the project I'm not using a Button
object - and a com.google.gwt.event.dom.client.ClickEvent
for it. I'm using a personalized widget:
package de.vogella.gwt.helloworld.client;
import com.smartgwt.client.widgets.Label;
public class buttonLabel extends Label
{
public buttonLabel (String text, String elementID)
{
super();
setContents(text);
setAutoWidth();
setBaseStyle("wwHoverLabel");
setShowRollOver(true);
}
}
and this use com.smartgwt.client.widgets.events.ClickHandler()
.
Anyway I do not know how to resolve this ....
I've created a small project with this issue where I've put also a Button
object (Save1
) and also a personalized button buttonLabel
(Save2) - both with clickhandlers
.
Here is the link where you can download sources of this small project I've created: link
Case1:
say for example we choose date 2011/02/16 and we change manually the date into 2011/02/17 and push the button Save1
- everything works fine - the date remains 2011/02/17
Case2-a - line
Window.alert("2 " + date.getValue());
un-commented:
say for example we choose date 2011/02/16 and we change manually the date into 2011/02/17 and push the button Save2
- in the warning message date value is 2011/02/16 but in the field date remains 2011/02/17
Case2-b - line
Window.alert("2 " + date.getValue());
uncommented:
say for example we choose date 2011/02/16 and we change manually the date into 2011/02/17 and push the button Save2
- the value from field date is automatically changed to 2011/02/16
Later later edit:
Since I can't figure out how to solve my problem I'm thinking for the moment at a temporary solution. So, I have:
DateItem date = new DateItem("Adate");
date.setWidth(120);
date.setWrapTitle(false);
date.setAttribute("useTextField", true);
date.setAttribute("inputFormat", "yyyy/MM/dd");
date.setAttribute("displayFormat", "toJapanShortDate");
Because the attribute useTextField
is set to true
we can see the text entry field. How can I make this text entry field to be un-editable. Actually I want to have only the possibility to choose the date from calendar and not to change it manually.
回答1:
The following code should work.
DateItem date = new DateItem("Adate");
date.setAttribute("useTextField", true);
date.setAttribute("inputFormat", "yyyy/MM/dd");
date.setAttribute("displayFormat", "toJapanShortDate");
TextItem textItem = new TextItem();
textItem.setAttribute("readOnly", "true");
date.setTextFieldProperties(textItem);
来源:https://stackoverflow.com/questions/4948142/date-browsers-problem-if-manually-changed-and-focus-on-it-did-not-save