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!
*This post is locked for comments
this is helpful
[quote user="Brad D"]I'm looking to either validate each field as it is changed or validate the entire dialog at once, but NOT allow it to close if validation fails.[/quote]
Take a look at
\Classes\InventABCUpdate\validate
method for example. There is few dialog fields validation presented.
you can create a runbase class dialog where on standrad validate method you can validate on fields before the dialog is closed.
Thanks,
Yousef Shawareb
Hi,
In this case you need to create a form as dialog. On the form you can add some validation before closing it. There are some examples in standard AX2009:
Form InventCostReportDialog which is called from report InventCostValue (method Dialog)
Form ProjEstimateListDialog which is called from report ProjEstimateList (method Dialog)
but you can also use a form-based dialog on classes.
regards,
André
Thanks for the hint. Unfortunately, this is what I have now. I'm looking to either validate each field as it is changed or validate the entire dialog at once, but NOT allow it to close if validation fails.
When I do it this way, the dialog closes whether or not validation passes or fails.
Thanks again.
Hi Brad,
You can start with the following example. Just copy and past it into a new job.
static void DialogJob1(Args _args)
{
Dialog dialog;
DialogField dialogField;
Name name;
;
dialog = new Dialog("please type ' abc'");
dialogField = dialog.addField(typeid(Name),"Type value" );
if (dialog.run())
{
name = dialogField.value();
if (name == 'abc')
info("well done, mate!");
else
throw error("This was the wrong value");
// add code after validation
}
else
{
warning("Update cancelled by user");
}
}
regards,
André
André Arnaud de Cal...
292,160
Super User 2025 Season 1
Martin Dráb
230,962
Most Valuable Professional
nmaenpaa
101,156