Twebhtmlanchor problem

I am trying to send an email with the contents of some edit fields.

  1. If I add a mailto link in the properties the link works fine and pops up the mail application. However if I use he onclick event or mouse down and add
webhtmlanchor2.HREF :=  'mailto:sales@rockstruck.com?subject=My Subject&body=This is the body%0D%0Aline2';

The property in the inspector changes and if I click the link it works. But the click fails.

  1. Ideally I want to use a submit button and hide the Twebhtmlanchor so on abutton click I tried
  webhtmlanchor2.HREF :=  'mailto:sales@rockstruck.com?subject=My Subject&body=This is the body%0D%0Aline2';
  WebHTMLAnchor2Click(Sender);

but this failed.

What mysterious magic do I need to get this working please.

What about just calling like this:

procedure TForm1.WebButton1Click(Sender: TObject);
begin
  window.open('mailto:sales@rockstruck.com?subject=My Subject&body=This is the body%0D%0Aline2');
end;

I wasn't aware of that thanks.

  1. How can I tie this into the required edit fields. IE only run the command when the submit is allowed.

  2. Also is it possible to use required on a combi dropdown and a memo field ?

Use a TWebHTMLForm and place your TWebEdit and TWebComboBox and TWebButton inside.
For TWebEdit just use the required property of the component.
For TWebComboBox do:

procedure TForm1.WebFormCreate(Sender: TObject);
begin
  WebComboBox1.ElementHandle.setAttribute('required', '');
end;

So button click will display the required messages, but I don't know IE much so you may need to set button type to submit but I am not sure of IE.

For the memo similar method should work

IE won't run the app anyway. Edge Chrome on window Chrome Safari n Mac are fine thanks.

Is there a way to stop the window.open code running if the 'required' is not met.

make your button type submit via component property.
Don't override the button click event.
And finally use the OnSubmit event of your TWebHTMLForm component to trigger window.open

procedure TForm1.WebHTMLForm1Submit(Sender: TObject);
begin
  window.open('mailto:sales@rockstruck.com?subject=My Subject&body=This is the body%0D%0Aline2');
end;