| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using InABox.Core;
- using InABox.Mobile;
- using Xamarin.Forms;
- namespace PRS.Mobile
- {
- public class DigitalFormStringEntry : MobileCard, IDigitalFormField<DFLayoutStringField, DFLayoutStringFieldProperties, string, string?>
- {
- private string _value = "";
- private readonly MobileEntry _entry;
-
- private DFLayoutStringField? _definition;
- public DFLayoutStringField? Definition
- {
- get => _definition;
- set
- {
- _definition = value;
- Initialize(value);
- }
- }
-
- public string Value
- {
- get => _value;
- set
- {
- _value = value;
- UpdateUI();
- }
- }
- private void UpdateUI()
- {
- _entry.Text = _value;
- }
- public bool IsEmpty => string.IsNullOrWhiteSpace(Value);
- private bool _readOnly;
- public bool ReadOnly
- {
- get => _readOnly;
- set
- {
- _readOnly = value;
- UpdateStatus();
- }
- }
-
- public void Deserialize(DFLoadStorageEntry entry)
- => Value = Definition?.Properties.DeserializeValue(entry) ?? string.Empty;
-
- public void Serialize(DFSaveStorageEntry entry)
- => entry.SetValue(Value);
- public event DigitalFormViewChangedHandler? ValueChanged;
- public DigitalFormStringEntry()
- {
- HeightRequest = 40;
- Padding = new Thickness(5,0);
-
- _entry = new MobileEntry()
- {
- Placeholder = "Enter answer",
- BackgroundColor = Color.Transparent
- };
- _entry.TextChanged += (o,e) =>
- {
- Value = _entry.Text;
- ValueChanged?.Invoke(this, new DigitalFormViewChangedArgs(Definition,Value));
- };
- Content = _entry;
- }
- private void Initialize(DFLayoutStringField? definition)
- {
- UpdateStatus();
- }
- private void UpdateStatus()
- {
- IsEnabled = !_readOnly && Definition?.Properties.Secure == false;
- var colors = DigitalFormUtils.GetColors(!IsEnabled, Definition?.Properties.Required ?? false, false);
- BackgroundColor = colors.Background;
- BorderColor = colors.Border;
- _entry.TextColor = colors.Foreground;
- }
-
- }
- }
|