日期浏览器问题 - 如果手动更改并关注它 - 未保存

发布于 2024-10-16 15:35:01 字数 4429 浏览 2 评论 0原文

我有一个与 smartgwt 中使用的日期类型相关的问题。

我将日期设置为可以手动更改它:

setAttribute("useTextField", true); 

在 Firefox 和 Chrome(也许还有其他浏览器,除了 Internet Explorer)中,如果首先我使用该弹出日历选择一个日期,然后手动更改它,然后让焦点位于日期字段并要保存文档(实际上是具有多个字段的表单)手动更改的日期会丢失,从保存的日历中选择的日期。 Internet Explorer 中不会发生这种情况。

在所有浏览器中,如果我从日历中选择一个日期,然后手动更改它并更改焦点,一切都会顺利 - 手动更改的日期将保存到数据库中。 需要一些建议。

非常感谢。

稍后编辑:

我正在使用com.smartgwt.client.widgets.form.fields.DateItem小部件

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");

我在 DynamicForm 上添加此日期:

DynamicForm  form = new DynamicForm();
form.setFields(date);

并将此表单添加到 VLayout 对象上:

VLayout editLayout = new VLayout(30);
editLayout.addMember(form);

问题在 Firefox 和 Firefox 等浏览器中重现。 Chrome 时:

  1. 我首先从日历中选择日期 - 假设我选择 2011/02/11
  2. 不会更改此日期字段的焦点
  3. 我正在手动更改 2011/02/12 中的日期 - 并且我 我正在按“保存”按钮。

完成这些步骤后,日期是 2011/02/11,而不是应有的 2011/02/12。 在 Internet Explorer 浏览器中没有发生 - 上述步骤后的日期是 2011/02/12!

稍后编辑

我使用 DataSource 来更新数据。

我有一个 UserObject ,在 userUpdate 方法中,我首先使用字段中的值(位于 DynamicForm 上)创建此用户对象) - 通过调用 generateUserObjectFromForm() 方法

UserObject   user = generateUserObjectFromForm(); 

在这里,在此方法中我正在执行以下操作: user.setAddedDate(date.getValueAsDate()), 但这里的 date.getValueAsDate() 值是从日历中选择的值,而不是手动修改的值。

我也尝试过:

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

但没有一个能正常工作。

我正在使用请求对象 (UserUpdateRequest) 来更新用户。

UserUpdateRequest 看起来像:


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);

在 RPC 用户更新方法上,我发送此 UserUpdateRequest 请求。

稍后编辑(2月15日):

我发现了为什么会发生与焦点相关的问题,这是因为在项目中我没有使用 Button 对象 -和一个 com.google.gwt.event.dom.client.ClickEvent 。我正在使用个性化小部件:

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);          
    }

}

并且使用 com.smartgwt.client.widgets.events.ClickHandler()

无论如何,我不知道如何解决这个问题......

我创建了一个带有此问题的小项目,其中还放置了一个 Button 对象(Save1)并还有一个个性化按钮 buttonLabel (Save2) - 都带有 clickhandlers

您可以通过以下链接下载我创建的这个小项目的源代码:链接

案例1: 举例来说,我们选择日期 2011/02/16,然后手动将日期更改为 2011/02/17 并按下按钮 Save1 - 一切正常 - 日期仍然是 2011/02/17

Case2-一条线 Window.alert("2 " + date.getValue()); 未注释: 举例来说,我们选择日期 2011/02/16,然后手动将日期更改为 2011/02/17 并按下按钮 Save2 - 在警告消息中,日期值为 2011/02/16,但在字段日期仍为 2011/02/17

Case2-b - 行 Window.alert("2 " + date.getValue()); 取消注释: 例如,我们选择日期 2011/02/16,然后手动将日期更改为 2011/02/17,然后按按钮 Save2 - 字段日期的值会自动更改为 2011/02/16

稍后编辑:

由于我不知道如何解决我的问题,所以我暂时正在考虑一个临时解决方案。 所以,我有:

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");

因为属性 useTextField 设置为 true 我们可以看到文本输入字段。我怎样才能使这个文本输入字段不可编辑。实际上我只想能够从日历中选择日期而不是手动更改它。

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:

  1. I'm selecting first the date from calendar - say I'm selecting 2011/02/11
  2. I'm changing the day in 2011/02/12 manually - and I'm not changing the focus from this date field
  3. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回梦 2024-10-23 15:35:01

下面的代码应该可以工作。

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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文