function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NikiVankerkNikiVankerk 

Action Region to avoid validation error also losing data on rerender

I have a situation where I have an optional lookup (PO Line Item) and a master detail field (Sub Account) on an Invoice record.  The PO Line Item object also links to a Sub Account and I want to default this Sub Account value from a selected PO Line Item into the Invoice's Sub Account field.  You don't always have to choose a PO Line Item; in the case that there is no PO you simply select a Sub Account manually.

 

To accomplish this I have an actionSupport component that calls a controller method onchange to run SOQL on the selected PO Line Item to pull its Sub Account into the invoice's Sub Account field.  The user is picking a PO Line Item before they have set a Sub Account, thus that MD field is blank when they select a PO Line Item.  This gives a validation error when the action function runs.  

 

To avoid the error, I added ActionRegion tags around the PO Line Item field so that only the PO Line Item value is sent.  But this means the rest of the data that I have entered so far is lost in the rerender.

 

Any thoughts on how to accomplish this - avoid the error on requiring a value in an MD field but keep the values in all the other fields after the rerender?

bob_buzzardbob_buzzard
Typically when you use an action region, you'd only rerender the part of the form bound by the action region.  That leaves the rest of the form as-is.

That's about the only way to do it I'm afraid - if you rerender any other part of the form the value from the controller will be used which will discard any user input as that hasn't been submitted yet.
NikiVankerkNikiVankerk
Thanks for the input - I ended up leaving the MD field off and using a different lookup field to the SubAccount on the page, then copying the value over to the MD field during the save.  Weird workaround but at least it lets me rerender the page without actionregion, avoiding losing my inputted data and not firing a validation error on the MD field.