Customizer
Customizer

Reputation: 61

Why does my PXSelector ignore what I have selected

I have created a PXGraphExtension on POLandedCostDocEntry. I have added a PXAction button. When the button is pressed I show a popup panel to ask the user for a landed cost code.

Popup panel asking for Landed Cost Code

The problem is that the PXSelector ignores whatever I enter into the field and resets to APPLE (or whatever Landed Cost Code is alphabetically first). If I use the Selector to choose a different code, the code I select is visible for a moment and then immediately replaced with APPLE again.

The ASPX for the popup dialog is as follows:

  <px:PXSmartPanel runat="server" ID="PanelAskForLCCode" LoadOnDemand="True" AutoRepaint="True" Key="LandedCostCodeSelection" CaptionVisible="True" Caption="Select Landed Cost Code" AcceptButtonID="CstButton4" CancelButtonID="CstButton5">
    <px:PXPanel runat="server" ID="CstPanel9">
      <px:PXFormView runat="server" ID="CstFormView10" SkinID="Transparent" Width="100%" SyncPosition="True" DataMember="LandedCostCodeSelection" DataSourceID="ds">
        <Template>
          <px:PXSelector runat="server" ID="CstPXSelector11" DataField="LandedCostCodeID" CommitChanges="True" DataSourceID="ds">
            </px:PXSelector>
        </Template>
      </px:PXFormView>
    </px:PXPanel>
    <px:PXPanel runat="server" ID="LandedCostCodeSelectionButtons" SkinID="Buttons">
      <px:PXButton runat="server" ID="CstButton4" DialogResult="OK" Text="OK" />
      <px:PXButton runat="server" ID="CstButton5" DialogResult="Cancel" Text="Cancel" />
    </px:PXPanel></px:PXSmartPanel>

The code for the view that I'm referencing in the dialog is:

public PXSelect<LandedCostCode> LandedCostCodeSelection;

The code that I'm using to call the dialog is:

   if (LandedCostCodeSelection.AskExt() == WebDialogResult.OK)
        {
          //rest of code here
        }

What am I missing to allow the user to select or type a different Landed Cost Code?

Edit 1: I have changed the code for the view that I'm referencing in the dialog to:

public PXFilter<LandedCostCode> LandedCostCodeSelection;

My aspx now looks like this:

<px:PXSmartPanel runat="server" ID="PanelAskForLCCode" Key="LandedCostCodeSelection" CaptionVisible="True" Caption="Select Landed Cost Code" AcceptButtonID="CstButton4" CancelButtonID="CstButton5" Width="300px" AutoRepaint="True" LoadOnDemand="True">
    <px:PXFormView runat="server" ID="CstFormView18" CaptionVisible="False" Caption="LC Code Selection" DataSourceID="ds" DataMember="LandedCostCodeSelection">
        <Template>
            <px:PXLayoutRule runat="server" ID="CstPXLayoutRule19" StartColumn="True" ControlSize="XM" LabelsWidth="S"/>
            <px:PXSelector runat="server" ID="CstPXSelector20" DataField="LandedCostCodeID" CommitChanges="True" DataSourceID="ds" DataMember="LandedCostCodeSelection"/>
        </Template>
        <CallbackCommands>
            <Search CommitChanges="True"/>
        </CallbackCommands>
    </px:PXFormView>
    <px:PXPanel runat="server" ID="LandedCostCodeSelectionButtons" SkinID="Buttons">
        <px:PXButton runat="server" ID="CstButton4" DialogResult="OK" Text="OK"/>
        <px:PXButton runat="server" ID="CstButton5" DialogResult="Cancel" Text="Cancel"/>
    </px:PXPanel>
</px:PXSmartPanel>

I'm calling the dialog as follows:

if (LandedCostCodeSelection.AskExt((graph, view) =>
{
  LandedCostCodeSelection.Cache.Clear();
},true) == WebDialogResult.OK)
{

} 

I notice that when I click on the selector button and pick a row from the selector (which briefly returns a value to the field which is then overwritten right away) when I click on the selector button again, the selector has remembered the record I last selected.

Finally, if I invoke the dialog as follows:

if (LandedCostCodeSelection.AskExt((graph, view) =>
{
  LandedCostCodeSelection.Cache.Clear();
  LandedCostCodeSelection.Current.LandedCostCodeID = "XYZ";
},true) == WebDialogResult.OK)
{

} 

Then the field is populated with XYZ and if I click OK I can reference the value of XYZ. (But if I use the selector, then the value is cleared and cannot be accessed again.)

Upvotes: 1

Views: 220

Answers (1)

Lucian
Lucian

Reputation: 309

The problem relies in the definition of the DataView and the DAC used. I have reproduced the issue and this is what I've changed to make it work:

Use a new custom DAC as a source for your view. Note that the field is not bound and is not key (does not have IsKey = true, as in LandedCostCode.LandedCostCodeID:

    [Serializable]
    [PXHidden]
    public partial class LandedCostCodeFilter: IBqlTable
    {
      #region LandedCostCodeID
      public abstract class landedCostCodeID : PX.Data.BQL.BqlString.Field<landedCostCodeID> { }
      [PXString(15, IsUnicode = true)]
      //[PXUnboudDefault("APPLE")] //optional, to preselect a value
      [PXUIField(DisplayName = "Landed Cost Code",Visibility=PXUIVisibility.SelectorVisible)]
      [PXSelector(typeof(Search<LandedCostCode.landedCostCodeID>))]
      public virtual String LandedCostCodeID {get; set}
      #endregion
    } 

Change the DataView definition, using a PXFilter instead of PXSelect and use the new DAC

public PXFilter<LandedCostCodeFilter> LandedCostCodeSelection; 

Correct that and your dialog should work.

Obs. If you want to have a value pre-selected when you open the dialog, add [PXUnboudDefault("APPLE")] to the field in the DAC

Not sure how does your button definition look like, but here is what it should be:

  public PXAction<POLandedCostDoc> SelectLandedCost;
  [PXButton]
  [PXUIField(DisplayName = "Select Landed Cost Code", MapEnableRights = PXCacheRights.Delete, MapViewRights = PXCacheRights.Delete)]
  protected void selectLandedCost()
  {
     if(LandedCostCodeSelection.AskExt(true) != WebDialogResult.OK) return;
    
     // do some stuff here
  }

Also, my aspx code:

<px:PXSmartPanel runat="server" ID="PanelAskForLCCode" Caption="Select Landed Cost Code" CaptionVisible="True" Key="LandedCostCodeSelection">
<px:PXFormView runat="server" ID="CstFormView2" DataMember="LandedCostCodeSelection" SkinID="Transparent" DataSourceID="ds" Height="100%" Width="100%">
  <Template>
    <px:PXLayoutRule runat="server" ID="CstPXLayoutRule3" StartColumn="True" />
    <px:PXSelector runat="server" ID="CstPXSelector4" DataField="LandedCostCodeID" CommitChanges="True" AutoRefresh="True" />
    <px:PXPanel runat="server" ID="LandedCostCodeSelectionButtons" SkinID="Buttons">
      <px:PXButton runat="server" ID="CstButton6" DialogResult="OK" Text="OK" />
      <px:PXButton runat="server" ID="CstButton7" DialogResult="Cancel" Text="Cancel" /></px:PXPanel></Template></px:PXFormView></px:PXSmartPanel>

Upvotes: 3

Related Questions