Axaptapedia is now maintained by AgileCadence For more information please click here.

Difference between revisions of "Mandatory DialogField"

From Axaptapedia
Jump to: navigation, search
m (Fix xpp formatting)
 
Line 3: Line 3:
  
 
1. Add '''mandatory()''' method into [[DialogField]] class:
 
1. Add '''mandatory()''' method into [[DialogField]] class:
<xpp>
+
<syntaxhighlight lang="xpp">
 
// Created by GRR on 01.11.2005
 
// Created by GRR on 01.11.2005
 
void mandatory(boolean r)
 
void mandatory(boolean r)
Line 19: Line 19:
 
         this.fieldControl().mandatory(r);
 
         this.fieldControl().mandatory(r);
 
}
 
}
</xpp>
+
</syntaxhighlight>
  
 
2. Add into '''unpack()''' method following lines:
 
2. Add into '''unpack()''' method following lines:
<xpp>
+
<syntaxhighlight lang="xpp">
 
case #PropertyMandatory:
 
case #PropertyMandatory:
 
     this.mandatory(unpackedProperties.valueIndex(i));
 
     this.mandatory(unpackedProperties.valueIndex(i));
 
     break;
 
     break;
</xpp>
+
</syntaxhighlight>
  
  

Latest revision as of 17:11, 27 September 2016

When adding controls to a standard form, either bound to a data field or not, one useful property is the Mandatory property. If this is set, then the control is shown with a red squiggly line if no value has been entered, and an error will automatically be shown when the user tries to save the record or close the form. This article describes how to also make this functionality available from dialog forms. You need to define the mandatory property in a DialogField class, as shown below.

1. Add mandatory() method into DialogField class:

// Created by GRR on 01.11.2005
void mandatory(boolean r)
{
    str name;
    // If properties exists then we are on server
    if (properties)
    {
        name = #Propertymandatory;
        if (! properties.exists(name))
            properties.add(name,true);
        properties.value(name,r);
    }
    else
        this.fieldControl().mandatory(r);
}

2. Add into unpack() method following lines:

case #PropertyMandatory:
    this.mandatory(unpackedProperties.valueIndex(i));
    break;


This solution was sourced from a post by Regards! Ruslan on the the microsoft.public.axapta.programming newsgroup.