For this, I would build a StringList class to define your list and values, and then use attributes to control the behavior.
First, the List class (combs)
public class Combs
{
//build string list attribute
public class ListAttribute : PXStringListAttribute
{
public ListAttribute() : base(new[]
{
Pair(Comb, "Comb"),
Pair(Other, "Other")
})
{ }
}
//declare constant values
public const string Comb = "Comb";
public const string Other = "Other";
//build constant for values you want to compare in BQL
public class other : PX.Data.BQL.BqlString.Constant<other>
{
public other() : base(Other) {; }
}
}
Next, are the properties/attributes:
#region UsrComb
[PXDBString]
[Combs.List]
[PXUIField(DisplayName = "Comb")]
public virtual string UsrComb { get; set; }
public abstract class usrComb : PX.Data.BQL.BqlBool.Field<usrComb> { }
#endregion
#region UsrText
[PXDBString]
[PXUIField(DisplayName = "Text")]
//pxdefault is required if you have a PXUIRequired attribute.
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIRequired(typeof(Where<usrComb, Equal<Combs.other>>))]
[PXUIVisible(typeof(Where<usrComb, Equal<Combs.other>>))]
[PXUIEnabled(typeof(Where<usrComb, Equal<Combs.other>>))]
public virtual String UsrText { get; set; }
public abstract class usrText : PX.Data.BQL.BqlString.Field<usrText> { }
#endregion
PXUIRequired/Enabled/Visible attributes then check to see if the list equals the constant. You can use any combination of the values.
Put your fields on a screen, and ensure UsrComb has CommitChanges set to True. You will change the value to Other and it will then show the text field, and hide it when set back.
If you wish to blank the value after the dropdown is changed away from other, you can use the following code:
protected virtual void CROpportunity_UsrComb_FieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e)
{
if (e.NewValue == null)
return;
string Comb = (string)e.NewValue;
if (Comb != Combs.Other)
sender.SetValueExt<CROpportunityExt.usrText>(e.Row, "");
}