Mobile Version of InputQuery

From UniGui
Jump to: navigation, search
rc := mInputQuery('How many units would you like to add to this building? (Maximum 10)', 'Number of Units?', sNumUnits, 'number');
Error creating thumbnail: File missing
Preview

Returns TRUE if the OK button was selected otherwise FALSE

Returns TRUE if the OK button was selected otherwise FALSE

The value typed in is returned in rtnValue

If you pass it an inputtype it will validate against HTML5 Input Types:

url For entering a URL. It must start with a valid URI scheme, (for example http://, ftp:// or mailto:).
tel For entering phone numbers. It does not enforce a particular syntax for validation, so if you want to ensure a particular format, you can use <a href="https://www.html5rocks.com/en/tutorials/forms/html5forms/#toc-vc-pattern">pattern</a>.
email For entering email addresses. By default it will only take one, but if the multiple attribute is provided, a comma separated list of email addresses is valid.
search A text input field styled in a way that is consistent with the platform's search field.
number For numeric input, can be any rational integer or float value.
color For choosing colors.
range For number input, but unlike the number input type, the value is less important. It is displayed to the user as a slider control.
datetime For entering a date and time value where the time zone is provided as GMT.
datetime-local For entering a date and time value where the time zone provided is the local time zone.
date For entering a date (only) with no time zone provided.
time For entering a time (only) with no time zone provided.
week For entering a date that consists of a week-year number and a week number, but no time zone.
month For entering a date with a year and a month, but no time zone.


I have only tested it with number, but the others should work


function mInputQuery(aPrompt: string; aTitle: String; var rtnValue: String; InputType: String=''): Boolean;
var
  fModal   : TUnimForm;
  aMsg     : TUnimlabel;
  aInput   : TUnimEdit;
  btnOK    : TunimButton;
  btnCancel: TunimButton;
begin
  result         := False;
  fModal         := TUnimForm.Create(UniApplication);
  fModal.Caption := aTitle;

  aMsg                  := TUnimlabel.Create(fModal);
  aMsg.Parent           := fModal;
  aMsg.Margins.Top      := 50;
  aMsg.Margins.Left     := 30;
  aMsg.Margins.Right    := 30;
  aMsg.AlignWithMargins := True;
  aMsg.Align            := alTop;
  aMsg.Caption          := aPrompt;

  aInput                  := TUnimEdit.Create(fModal);
  aInput.Parent           := fModal;
  aInput.Margins.Top      := 50;
  aInput.Margins.Left     := 30;
  aInput.Margins.Right    := 30;
  aInput.AlignWithMargins := True;
  aInput.Align            := alTop;
  if (InputType <> '') then
    (aInput as IUniJSInterface).JSConfig('inputType', [''+InputType+'']);

  btnCancel             := TunimButton.Create(fModal);
  btnCancel.Parent      := fModal;
  btnCancel.Caption     := 'Cancel';
  btnCancel.Width       := Trunc((UniApplication.ScreenWidth - (2 * aMsg.Margins.Left)) / 2 - (aMsg.Margins.Left / 2));
  btnCancel.Top         := aMsg.Margins.Top + aMsg.Height + aInput.Height + 20 + (fModal.Height - fModal.ClientHeight);
  btnCancel.Left        := aMsg.Margins.Left;
  btnCancel.ModalResult := mrCancel;

  btnOK             := TunimButton.Create(fModal);
  btnOK.Parent      := fModal;
  btnOK.Caption     := 'OK';
  btnOK.Width       := btnCancel.Width;
  btnOK.Left        := UniApplication.ScreenWidth - aInput.Margins.Right - btnOK.Width;
  btnOK.Top         := aMsg.Margins.Top + aMsg.Height + aInput.Height + 20 + (fModal.Height - fModal.ClientHeight);
  btnOK.ModalResult := mrOk;

  result := (fModal.ShowModal() = mrOk);

  rtnValue := aInput.Text;
end;