如何根据下拉列表清除值并清除以前的表单值?

时间:2022-09-04 23:07:24

I have a requirement where based on the dropdown values, it should default a checkbox or field to a certain value.

我有一个要求,根据下拉值,它应该将复选框或字段默认为某个值。

So let's say the values for the dropdown are: 1, 2, and 3. If I select 1, a checkbox should be checked. If 2 or 3 is selected, a field should have the default value of "983.3".

因此,我们假设下拉列表的值为:1,2和3.如果我选择1,则应选中一个复选框。如果选择2或3,则字段的默认值应为“983.3”。

The question I'm asking is: How do I clear the checkbox/all form fields upon selection of another dropdown value (2 or 3) after selecting 1? This is so only the conditional default values for 1 or 2/3 will appear on the form based upon selection.

我问的问题是:在选择1之后,如何在选择另一个下拉值(2或3)时清除复选框/所有表单字段?这样只有1或2/3的条件默认值将根据选择出现在表单上。

1 个解决方案

#1


1  

I will assume that all your fields are bound to a database table.

我将假设您的所有字段都绑定到数据库表。

Then add the modifiedField method on the table:

然后在表上添加modifiedField方法:

public void modifiedField(fieldId _fieldId)
{
    super(_fieldId);
    switch (_fieldId)
    {
        case fieldNum(YourTable,YourDropdown):
            switch (this.YourDropdown)
            {
                case 1:
                    this.YourCheckBox = NoYes::Yes;
                    this.YourField = 0;
                    break;
                case 2, 3:
                    this.YourCheckBox = NoYes::No;
                    this.YourField = 983.3;
                    break;
            }
            break;
    }
}

The update of form fields happens automatically.

表单字段的更新自动发生。

#1


1  

I will assume that all your fields are bound to a database table.

我将假设您的所有字段都绑定到数据库表。

Then add the modifiedField method on the table:

然后在表上添加modifiedField方法:

public void modifiedField(fieldId _fieldId)
{
    super(_fieldId);
    switch (_fieldId)
    {
        case fieldNum(YourTable,YourDropdown):
            switch (this.YourDropdown)
            {
                case 1:
                    this.YourCheckBox = NoYes::Yes;
                    this.YourField = 0;
                    break;
                case 2, 3:
                    this.YourCheckBox = NoYes::No;
                    this.YourField = 983.3;
                    break;
            }
            break;
    }
}

The update of form fields happens automatically.

表单字段的更新自动发生。