Commit d750eeec authored by Carsten  Rose's avatar Carsten Rose
Browse files

#3711 / Upload Button opens the camera on a smartphone.

Manual.rst: add description for new attribute 'capture'.
AbstractBuildForm.php: implement adding attribute.
parent 5093db76
......@@ -2271,6 +2271,9 @@ and will be processed after saving the primary record and before any action Form
* *FormElement.parameter*:
* *capture=camera*: On a smartphone, after pressing the 'open file' button, the camera will be opened and a
choosen picture will be uploaded. Automatically set/overwrite `accept=image/*`.
* *accept*: `<mime type>,image/*,video/*,audio/*,.doc,.docx,.pdf`
* List of mime types (also known as 'media types'): http://www.iana.org/assignments/media-types/media-types.xhtml
......
......@@ -300,6 +300,7 @@ abstract class AbstractBuildForm {
return $html;
}
/**
* Build an assoc array with standard form attributes.
*
......@@ -2490,6 +2491,11 @@ abstract class AbstractBuildForm {
$formElement[FE_FILE_MIME_TYPE_ACCEPT] = UPLOAD_DEFAULT_MIME_TYPE;
}
Support::setIfNotSet($formElement, FE_FILE_CAPTURE);
if ($formElement[FE_FILE_CAPTURE] == FE_FILE_CAPTURE_CAMERA) {
$formElement[FE_FILE_MIME_TYPE_ACCEPT] = 'image/*';
}
# Build param array for uniq SIP
$arr = array();
$arr['fake_uniq_never_use_this'] = uniqid(); // make sure we get a new SIP. This is needed for multiple forms (same user) with r=0
......@@ -2511,6 +2517,7 @@ abstract class AbstractBuildForm {
// $attribute .= Support::doAttribute('class', 'form-control');
$attribute .= Support::doAttribute('type', 'file');
$attribute .= Support::doAttribute('title', $formElement['tooltip']);
$attribute .= Support::doAttribute(FE_FILE_CAPTURE, $formElement[FE_FILE_CAPTURE], true);
$attribute .= $this->getAttributeList($formElement, [FE_AUTOFOCUS, FE_FILE_MIME_TYPE_ACCEPT]);
$attribute .= Support::doAttribute('data-load', ($formElement[FE_DYNAMIC_UPDATE] === 'yes') ? 'data-load' : '');
$attribute .= Support::doAttribute('data-sip', $sipUpload);
......
......@@ -692,6 +692,7 @@ const FE_FILE_REPLACE_MODE = 'fileReplace'; // Target pathFilename for an upload
const FE_FILE_REPLACE_MODE_ALWAYS = 'always'; // Target pathFilename for an uploaded file.
const FE_FILE_MIME_TYPE_ACCEPT = 'accept'; // Target pathFilename for an uploaded file.
const FE_FILE_MAX_FILE_SIZE = 'maxFileSize'; // Target pathFilename for an uploaded file.
const FE_FILE_CAPTURE = 'capture'; // On a smartphone opens the camera
const FE_SQL_VALIDATE = 'sqlValidate'; // Action: Query to validate form load
const FE_EXPECT_RECORDS = 'expectRecords'; // Action: expected number of rows of FE_SQL_VALIDATE
const FE_MESSAGE_FAIL = 'messageFail'; // Action: Message to display, if FE_SQL_VALIDATE fails.
......@@ -761,6 +762,7 @@ const FE_HTML_ID = 'htmlId'; // Will be dynamically computed during runtime.
// Values
const FE_ENCODE_SPECIALCHAR = 'specialchar';
const FE_ENCODE_NONE = 'none';
const FE_FILE_CAPTURE_CAMERA = 'camera';
// FormElement Types
const FE_TYPE_UPLOAD = 'upload';
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment