Jump to content

Retrieving file name from TW3EditBox


Recommended Posts

I've set an input field as follows:

  edPhoto1.InputType := itFile;
  w3_setAttrib(edPhoto1.Handle, 'id', 'cameraInput');
  w3_setAttrib(edPhoto1.Handle, 'capture', 'camera');
  w3_setAttrib(edPhoto1.Handle, 'accept', 'image/jpg');

But seem I can't retreive the selected file name in edPhoto1.Text or Value property.
 

Link to post
Share on other sites
  • Moderators
accept
If the value of the type attribute is file, then this attribute will indicate the types of files that the server accepts, otherwise it will be ignored. The value must be a comma-separated list of unique content type specifiers:
  • A file extension starting with the STOP character (U+002E). (e.g. .jpg, .png, .doc).
  • A valid MIME type with no extensions.
  • audio/* representing sound files. HTML5
  • video/* representing video files. HTML5
  • image/* representing image files. HTML5

 

capture

When the value of the type attribute is file, the presence of this Boolean attribute indicates that capture of media directly from the device's environment using a media capture mechanism is preferred.

 

examples

accept="image/*" capture="user"
accept="video/*" capture="environment"
accept="audio/*" capture

if you don't specify the capture attribute for images, your file picker will display a file list of available images. If you do, it displays the actual image.

Note :

the editbox will display the filename, however the content of the EditBox1.Text property will be "C:\fakepath\" + filename

see

 
does this help ?
Link to post
Share on other sites

Thank you for the references, I've been able to better tune the attributes.
- seems 'image/*' is not the better choice as it only provide access to the camera.
- capture is not used, may be depending on mobile browser...
 

  edPhoto1.InputType := itFile;
  w3_setAttrib(edPhoto1.Handle, 'accept', 'image/png, image/jpg');
  w3_setAttrib(edPhoto1.Handle, 'capture', '');

 

But still I can't retrieve the name of the selected file

filename := edPhoto1.Text;

filename := w3_getStyle(edPhoto1.Handle, 'value');

procedure TFMyForm.edPhoto1Changed(Sender: TObject);
begin
  filename := edPhoto1.Text;
end;


 

 

Link to post
Share on other sites
  • Moderators

not sure what you mean

a form with an editbox and a button, and your snippet :

procedure TForm1.W3Button1Click(Sender: TObject);
begin
  writeln(edPhoto1.Text);
end;

procedure TForm1.InitializeForm;
begin
  inherited;
  // this is a good place to initialize components
  edPhoto1.InputType := itFile;
  w3_setAttrib(edPhoto1.Handle, 'accept', 'image/png, image/jpg');
  w3_setAttrib(edPhoto1.Handle, 'capture', '');
end;

works fine. The filename comes up in the console as C:\fakepath\testimage.png  [line #433]

BTW : The above code is still tricky in that it refers to the handle of the editbox in the initializeForm proc. Handle is only valid if and when it exists in the dom. The  set_Attrib method (SmartCL.System) does test if the handle is valid but if it is not, those calls will obviously fail.

Better be safe and wrap it in a readyexecute call (handle here refers to the form)

Handle.ReadyExecute( procedure ()
  begin
  w3_setAttrib(edPhoto1.Handle, 'accept', 'image/png, image/jpg');
  w3_setAttrib(edPhoto1.Handle, 'capture', '');
end);

at least then you can be sure the setAttrib calls refer to something in existence.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...