服务器端修改后如何更新将表单标记为脏

发布于 2025-01-20 05:22:52 字数 1146 浏览 3 评论 0原文

我不明白如何使客户端UI意识到文档中的服务器端更改。

我的用例是:我正在向我的表单添加一个按钮,该按钮调用自定义文档方法:

在mydoctype.py中,我有:

class MyDocType(Document):

    @frappe.whitelist()
    def change_some_value_in_doc(self):

        self.the_field_i_want_to_change = 50

它可以使用the_field_i_want_to_change立即更新为新值。

但是,如果我点击保存,我会收到消息“文档中没有更改” 。我设法确定这是因为在JS方面,该表格并未标记为“肮脏”,但是尽管一遍又一遍地阅读文档,但我找不到正确的方法。

我尝试使用self.notify_update(),似乎没有效果。

是一个错误吗?还是我误解了应该如何工作?

我正在使用frappe v 14.0.0-beta.3

[编辑]

实际上,我意识到确实

class MyDocType(Document):

    @frappe.whitelist()
    def change_some_value_in_doc(self):

        self.the_field_i_want_to_change = 50
        self.save()

可以在保存新值的意义上确实有效,但这并不是我想要的,因为我的目的实际上是要使用自定义方法预填充一些数据,然后留给用户在保存之前完成……

任何帮助我朝正确方向朝着正确的方向发展的帮助将不胜感激。

I don't understand how to make the Client ui aware of a server side change in a document.

My use case is the following : I'm adding a button to my form, that calls a custom document method :
The custom button

In MyDocType.py, I have :

class MyDocType(Document):

    @frappe.whitelist()
    def change_some_value_in_doc(self):

        self.the_field_i_want_to_change = 50

It work in the sense that the_field_i_want_to_change is immediately updated to the new value.

However, If I hit Save, I get the message "No changes in document". I managed to determine that this is because on the JS side, the form is not marked as "dirty", but despite reading the documentation over and over, I cannot find the right way.

I tried with self.notify_update() which seems to have no effect.

Is it a bug ? Or am I misunderstanding how this is supposed to work ?

I'm using frappe v 14.0.0-beta.3

[EDIT]

Actually, I realized that doing

class MyDocType(Document):

    @frappe.whitelist()
    def change_some_value_in_doc(self):

        self.the_field_i_want_to_change = 50
        self.save()

Does work in the sense that it save the new value, but it's not exactly what I'm looking for, because my purpose is actually to pre-fill some data with the custom method and leave to the user to complete before saving...

Any help to get me in the right direction would be very appreciated.

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

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

发布评论

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

评论(1

無處可尋 2025-01-27 05:22:52

要在表单中预填充数据 - 您希望用户在保存到数据库之前确认该数据,您应该使用客户端脚本(在 JS 中)。更改服务器上的值不会对您有帮助,因为您希望用户在向数据库中插入记录之前获取预先填充的值。

To pre-fill data in your form - that you want the user to confirm before saving to the database, you should use client-side scripting (in JS). Changing the value on the server is not going to help you since you want the user to get pre-filled values before inserting a record in the database.

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