Axapta 对话框验证

发布于 2024-08-10 19:11:10 字数 244 浏览 3 评论 0原文

我在网上发现了一些关于在对话框中验证表单字段的帖子和文章,但我发现的示例似乎都无法正常工作。

有人可以发布一个完整、简洁的 x++ 代码示例,该示例生成一个包含单个文本字段的对话框,对其执行简单的验证(如果 text =“abc”),并且如果验证通过则关闭窗口(返回字段值)或如果验证失败,则会生成信息日志警告而不关闭对话框。

对于我们这些刚开始使用 x++ 的人来说,我认为拥有一个实际的工作示例将是一个很好的起点。

谢谢!

I've found several posts and articles around the net talking about validating form fields in dialogs, but none of the examples I've found seem to work properly.

Can someone post a complete, concise example of x++ code that generates a dialog containing a single text field, performs simple validation (if text = "abc") on it, and either closes the window (returning the field value) if validation passes or generates an Infolog warning without closing the dialog if validation fails.

For those of us just beginning in x++, I think it would be a great starting point to have an actual working example to build on.

Thanks!

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

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

发布评论

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

评论(2

日暮斜阳 2024-08-17 19:11:10

以下是 AX 2009 中如何使用 RunBase 类构建简单对话框的示例。在其中,我创建了一个名为 DialogExample 的类并派生自 RunBase。要显示对话框,您只需运行该类,但通常这可以通过将 MenuItem 指向该类来完成。

public class DialogExample extends RunBase
{
    DialogField dialogName;
    Name name;

    #DEFINE.CurrentVersion(1)
    #LOCALMACRO.CurrentList
        name
    #ENDMACRO
}

Object dialog()
{
    Dialog dialog = super();
    ;

    // Add a field for a name to the dialog. This will populate the field with 
    // any value that happens to be saved in name from previous uses of the
    // dialog.
    dialogName = dialog.addFieldValue(TypeId(Name), name);

    return dialog;
}

boolean getFromDialog()
{
    ;

    // Retrieve the current value from the dialog.
    name = dialogName.value();

    return true;
}

boolean validate(Object _calledFrom = null)
{
    boolean isValid;

    isValid = super(_calledFrom);


    // Perform any validation nessecary.
    if (name != 'abc')
    {
        isValid = checkFailed('Name is not equal to abc') && isValid;
    }

    return isValid;
}

Name parmName()
{
    ;

    return name;
}

public container pack()
{
    return [#CurrentVersion,#CurrentList];
}

public boolean unpack(container _packedClass)
{
    int version = conpeek(_packedClass, 1);

    switch (version)
    {
        case #CurrentVersion:
            [version,#CurrentList] = _packedClass;
            break;
        default :
            return false;
    }

    return true;
}

public static void main(Args args)
{
    DialogExample DialogExample;
    ;

    dialogExample = new dialogExample();

    // Display the dialog. This only returns true if the the user clicks "Ok" 
    // and validation passes.
    if (dialogExample.prompt())
    {
        // Perform any logic that needs to be run.
        info(dialogExample.parmName());
    }
}

通常,在这种情况下,需要运行的逻辑将被放入类的 run 方法中,然后在单击“确定”按钮时从 main 调用。由于 run 方法是一个实例方法,因此不需要 parm 方法来访问对话框上字段的值。

Here is an example in AX 2009 of how to build a simple dialog using the RunBase class. In it I create a class called DialogExample and derive from RunBase. To show the dialog you simply need to run the class, but typically this would be done by pointing a MenuItem at the class.

public class DialogExample extends RunBase
{
    DialogField dialogName;
    Name name;

    #DEFINE.CurrentVersion(1)
    #LOCALMACRO.CurrentList
        name
    #ENDMACRO
}

Object dialog()
{
    Dialog dialog = super();
    ;

    // Add a field for a name to the dialog. This will populate the field with 
    // any value that happens to be saved in name from previous uses of the
    // dialog.
    dialogName = dialog.addFieldValue(TypeId(Name), name);

    return dialog;
}

boolean getFromDialog()
{
    ;

    // Retrieve the current value from the dialog.
    name = dialogName.value();

    return true;
}

boolean validate(Object _calledFrom = null)
{
    boolean isValid;

    isValid = super(_calledFrom);


    // Perform any validation nessecary.
    if (name != 'abc')
    {
        isValid = checkFailed('Name is not equal to abc') && isValid;
    }

    return isValid;
}

Name parmName()
{
    ;

    return name;
}

public container pack()
{
    return [#CurrentVersion,#CurrentList];
}

public boolean unpack(container _packedClass)
{
    int version = conpeek(_packedClass, 1);

    switch (version)
    {
        case #CurrentVersion:
            [version,#CurrentList] = _packedClass;
            break;
        default :
            return false;
    }

    return true;
}

public static void main(Args args)
{
    DialogExample DialogExample;
    ;

    dialogExample = new dialogExample();

    // Display the dialog. This only returns true if the the user clicks "Ok" 
    // and validation passes.
    if (dialogExample.prompt())
    {
        // Perform any logic that needs to be run.
        info(dialogExample.parmName());
    }
}

Typically in this scenario logic that needs to be run would be put in a run method on the class and then called into from main if the Ok button is clicked. Since the run method would be an instance method this gets rid of the need for the parm methods to access the value of the field on the dialog.

囚你心 2024-08-17 19:11:10

我知道这是一个老问题,但还应该注意的是,对于刚开始 AX 开发领域的人来说,AOT 中有很好的工作代码示例,请查找具有前缀“Tutorial_”的表单和类。

Tutorial_RunBaseForm 是 AOT 中的一个类,它可以满足您的需求。

I know this is an old question but it should also be noted that for people starting out in the world of AX development, there are great working code examples in the AOT, look for the Forms and Classes which have the prefix "Tutorial_".

Tutorial_RunBaseForm is a class in the AOT which gives you exactly what you need.

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