Skip to content

A small plugin for Frappe that adds the support of customizations to the attach control.

License

Notifications You must be signed in to change notification settings

Digital-Box-Agency/frappe-better-attach-control

 
 

Repository files navigation

Frappe Better Attach Control

A small plugin for Frappe that adds customization to the attach control. It supports RTL layout and dark mode out of the box.

⚠️ v2 is still in BETA stage ⚠️


If you would like to buy me a cup of coffee 😎


Status

  • Desk: 🔵 Testing
  • Web Form: 🔵 Testing

Special Thanks

A simple display of gratitude and appreciation to those who provided helped and kind support.

Version 2

Version 1


Table of Contents


Requirements

  • Frappe >= v12.0.0

Setup

⚠️ Do not forget to replace [sitename] with the name of your site in all commands. ⚠️

Install

  1. Go to bench directory
cd ~/frappe-bench
  1. Get plugin from Github

(Required only once)

bench get-app https://github.com/kid1194/frappe-better-attach-control
  1. Build plugin

(Required only once)

bench build --app frappe_better_attach_control
  1. Install plugin on a specific site
bench --site [sitename] install-app frappe_better_attach_control
  1. Check the usage section below

Update

  1. Go to app directory
cd ~/frappe-bench/apps/frappe_better_attach_control
  1. Get updates from Github
git pull
  1. Go to bench directory
cd ~/frappe-bench
  1. Build plugin
bench build --app frappe_better_attach_control
  1. Update a specific site
bench --site [sitename] migrate
  1. (Optional) Restart bench
bench restart

Uninstall

  1. Go to bench directory
cd ~/frappe-bench
  1. Uninstall plugin from a specific site
bench --site [sitename] uninstall-app frappe_better_attach_control
  1. Remove plugin from bench
bench remove-app frappe_better_attach_control
  1. (Optional) Restart bench
bench restart

Usage

  1. Go to Customization > Customize Form

  2. Enter the form type/name (Ex: 'User')

  3. Scroll down to the form fields area

  4. Create an Attach or Attach Image field or edit an existing custom field

  5. Inside the field's custom property, Better Attach Options, add a JSON string of the options you want.

    Ex: {"allowed_file_types": [".jpg", ".png", ".gif"]}

Remember
  1. You can't modify the original fields of a doctype, so create a new field or clone and modify the entire doctype.
  2. Use the custom field property called Better Attach Options, that appears for Attach & Attach Image fields, instead of the default Options field property.

Available Field Options

Option Description
dialog_title 🔴 Upload dialog title to be displayed (✴️Frappe >= v14.0.0).

- Example: "Upload Images"
- Default: "Upload"
upload_notes Upload text to be displayed.

- Example: "Only images and videos, with maximum size of 2MB, are allowed to be uploaded"
- Default: ""
disable_file_browser 🔴 Disable file browser uploads.

- Default: false
allow_multiple Allow multiple uploads.

⚠️ (Field value is a JSON array of files url)

- Default: false
max_file_size Maximum file size (in bytes) that is allowed to be uploaded.

- Example: 2048 for 2KB
- Default: Value of maximum file size in Frappe's settings
allowed_file_types Array of allowed file types (mimes) or extensions to upload. Prefix escaped RegExp string types with $.

⚠️ (File extensions must have a leading dot ".")
⚠️ (RegExp string types will not be used to in HTML accept attribute)

- Example: ["image/*", "video/*", ".pdf", ".doc", "$audio\/([a-z]+)"]
- Default: null or ["image/*"]
max_number_of_files Maximum number of files allowed to be uploaded if multiple upload is allowed.

⚠️ (Bypassing the maximum attachments of doctype might not work)

- Example: 4
- Default: Value of maximum attachments set for the doctype
crop_image_aspect_ratio Crop aspect ratio for images (✴️Frappe >= v14.0.0).

- Example: 1 or 16/9 or 4/3
- Default: null
as_public Force uploads to be saved in public folder by default.

- Default: false
allowed_filename 🔴 Only allow files that match a specific file name to be uploaded.

- Example: (String)"picture.png" or (RegExp String)"/picture\-([0-9]+)\.png/"
- Default: null
allow_reload Allow reloading attachments (✴️Frappe >= v13.0.0).

ℹ️ Affect the visibility of the reload button.ℹ️

- Default: true
allow_remove Allow removing and clearing attachments.

ℹ️ Affect the visibility of the remove and clear buttons.ℹ️

- Default: true

Available JavaScript Methods

Method Description
enable_reload() Allow reloading attachments and show the reload button (Frappe >= v13.0.0).
disable_reload() Deny reloading attachments and hide reload button (Frappe >= v13.0.0).
enable_remove() Allow removing and clearing attachments and show the clear and remove buttons.
disable_remove() Deny removing and clearing attachments and hide the clear and remove buttons.
set_options(JSON) Set or change the plugin current options.

Supported Fields

  • Attach
  • Attach Image

Issues

If you find bug in the plugin, please create a bug report and let us know about it.


License

This repository has been released under the MIT License.

About

A small plugin for Frappe that adds the support of customizations to the attach control.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 94.7%
  • Python 3.5%
  • CSS 1.8%